×

Discussion Board

Page 2 of 2 FirstFirst 12
Results 16 to 18 of 18
  1. #16
    letdocoding
    Guest

    Re: How to open web page in J2Me Midlet?

    Also, the Server pgm, SPPlinkServer, is as follows.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.microedition.io.*;
    import java.io.*;
    import java.net.*;
    import javax.bluetooth.*;
    import javax.bluetooth.RemoteDevice;



    public class SPPlinkServer implements ActionListener, Runnable{

    LocalDevice device;
    DiscoveryAgent agent;
    String HTBTurl = null;
    Boolean mServerState = false; // stop is default state

    Thread mServer = null;
    String msgOut = "srv out msg";
    String msgIn = "no msg rcv";
    StreamConnectionNotifier btServerNotifier;
    UUID uuid = new UUID("9106", true);

    JLabel spacerlabel = new JLabel(" ");

    JButton startButton = new JButton("Start Server");
    JTextArea textarea = new JTextArea("",20, 40);
    JButton endButton = new JButton("End Server");

    public SPPlinkServer(){

    //Give it the Java look and feel
    JFrame.setDefaultLookAndFeelDecorated(true);

    JFrame frame = new JFrame("FileServer ");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JScrollPane scrollPane = new JScrollPane(textarea);
    textarea.setEditable(false);

    Container cp = frame.getContentPane();
    cp.setLayout(new BoxLayout(cp, BoxLayout.Y_AXIS));

    startButton.setAlignmentX(Component.CENTER_ALIGNMENT);
    startButton.addActionListener(this);
    cp.add(startButton);

    endButton.setAlignmentX(Component.CENTER_ALIGNMENT);
    endButton.addActionListener(this);
    cp.add(endButton);


    spacerlabel.setAlignmentX(Component.CENTER_ALIGNMENT);
    cp.add(spacerlabel);

    scrollPane.setAlignmentX(Component.CENTER_ALIGNMENT);
    cp.add(scrollPane);

    frame.pack();
    frame.setVisible(true);

    updateStatus("[server:] FileServer Application started");
    updateStatus("[server:] Press the \"Start Server\" button to await for client devices");


    }

    private void startServer()
    {
    if (mServer !=null)
    return;
    //start the server and receiver
    mServer = new Thread(this);
    mServer.start();
    }

    private void endServer() {
    if (mServer == null)
    return;
    try {
    mServer.join();
    } catch (Exception ex) {};
    mServer = null;

    }

    @Override
    public void run()
    {
    try {
    UUID uuid = new UUID("9106", true);
    device = LocalDevice.getLocalDevice(); // obtain reference to singleton
    device.setDiscoverable(DiscoveryAgent.GIAC); // set Discover mode to LIAC
    }catch (Exception e)
    {
    System.err.println("Cant init set discvover");
    e.printStackTrace();
    }

    String url = "btspp://localhost:" + uuid + ";name=BTTP;authenticate=false;master=false;encrypt=false";

    try{

    // obtain connection and stream to this service
    btServerNotifier = (StreamConnectionNotifier) Connector.open( url );
    } catch ( Exception e)
    {
    e.printStackTrace();
    }

    while (mServerState )
    {
    StreamConnection btConn = null;
    try {
    updateStatus("[server:] Now waiting for a client to connect");
    btConn = btServerNotifier.acceptAndOpen();
    RemoteDevice dev = RemoteDevice.getRemoteDevice(btConn);

    System.out.println("Remote device address: "+dev.getBluetoothAddress());

    updateStatus("Remote device "+dev.getFriendlyName(true)+"connected");

    }
    catch (IOException ioe)
    {

    }
    if (btConn != null) processConnection(btConn);
    }
    }

    void processConnection(StreamConnection conn)
    {
    // A client is now connected
    String str=null;
    DataInputStream in=null;
    try
    {


    //Reading data--------stream open
    in=conn.openDataInputStream();

    //reading URL and displaying it on the command prompt
    byte[] b=new byte[64];
    int p= in.read(b);
    System.out.print("data read " +p);
    str=new String(b);
    System.out.println(str);
    str=str.substring(1);
    System.out.println(str);

    updateStatus("request for url:"+str);
    } catch (Exception e)
    {
    e.printStackTrace();

    }

    try
    {
    //reading Webcontent and displaying it on the command prompt
    URL url= new URL(str);
    URLConnection yc=url.openConnection();
    HttpURLConnection inpcon = (HttpURLConnection)yc;
    InputStream b_in=inpcon.getInputStream();
    DataOutputStream out=conn.openDataOutputStream();
    byte[] fileAsBytes = new byte[1024];
    while(b_in.read(fileAsBytes)>0)
    { out.write(fileAsBytes);
    System.out.println(new String(fileAsBytes));
    }

    b_in.close();
    out.close();
    System.out.println("Data sent");
    in.close();

    } catch (Exception e)
    {
    e.printStackTrace();

    }

    try
    {
    conn.close();
    updateStatus("[server:] Finished connection");

    }catch (Exception e ){ }
    }

    @Override
    public void actionPerformed(ActionEvent e)
    {

    if ((e.getActionCommand()).equals("Start Server") )
    {
    startButton.setEnabled(false);
    mServerState = true; // set server state started
    startServer();
    }

    if ((e.getActionCommand()).equals("End Server") )
    {
    endButton.setEnabled(false);
    startButton.setEnabled(true);
    mServerState = false;
    endServer();
    }

    }

    public void updateStatus(String message)
    {
    textarea.append("\n" + message);
    }


    public static void main(String[] args)
    {
    new SPPlinkServer();
    }
    }
    Plz help...

  2. #17
    Registered User
    Join Date
    Oct 2013
    Posts
    1

    Re: How to open web page in J2Me Midlet?

    HELLOOO, I AM SURE I AM IN THE WRONG PLACE BUT I WILL BE GRATEFUL IF SOMEONE CAN HELP ME OUT. SINCE I UPDATED MY PC SUITE TO VERSION 3.8.48 I CAN NEITHER MAKE CALLS NOR VIEW CALL INFORMATION VIA PC SUITE/BLUETOOTH ANY MORE. IF THIS IS AN ERROR I WILL BE GRATEFUL IF I AM TOLD HOW TO RECTIFY IT. MY PHONE IS C2-3. THANKS

  3. #18
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,684

    Re: How to open web page in J2Me Midlet?

    Quote Originally Posted by azeez17 View Post
    HELLOOO, I AM SURE I AM IN THE WRONG PLACE BUT I WILL BE GRATEFUL IF SOMEONE CAN HELP ME OUT. SINCE I UPDATED MY PC SUITE TO VERSION 3.8.48 I CAN NEITHER MAKE CALLS NOR VIEW CALL INFORMATION VIA PC SUITE/BLUETOOTH ANY MORE. IF THIS IS AN ERROR I WILL BE GRATEFUL IF I AM TOLD HOW TO RECTIFY IT. MY PHONE IS C2-3. THANKS
    You can find PC Suite-related discussions on http://www.nokia.com/discussions - you can use the same user name+password there as you are using here.

Similar Threads

  1. Open C FAQ
    By Nokia Ron in forum Open C/C++
    Replies: 4
    Last Post: 2010-10-01, 09:02
  2. How to browse web page through in J2ME
    By sumeshchakra in forum Mobile Java Networking & Messaging & Security
    Replies: 3
    Last Post: 2010-01-11, 10:44
  3. How to make a WORKING J2ME Web Services client?
    By ebigogno in forum Mobile Java Networking & Messaging & Security
    Replies: 3
    Last Post: 2009-03-19, 12:24
  4. 技术文档:MIDP 2.0安全机制 与 MIDlet 数字签名
    By wotrust in forum [Archived] Other Programming Discussion 关于其他编程技术的讨论
    Replies: 0
    Last Post: 2006-12-30, 07:42

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×