Question

    wireless toolkit code

//j2me code for client mobile

    public class TCPConnectSend extends MIDlet implements CommandListener {
    Display display;

    public TCPConnectSend0 () {
    frm = new Form ("TCPConnectSend0");
    sendCmd = new Command("Send",Command.SCREEN, 1);
    frm.addCommand(sendCmd);
    frm.setCommandListener(this);
    text = new TextField("text:","",40,TextField.ANY);
    frm.append(text);
    }
    public void startApp() {
    if(display==null) {
    display = Display.getDisplay (this);
    }
    display.setCurrent(frm);
    try {
    conn=(SocketConnection)Connector.open("socket://|ip-address|:80");//socket connection to the server

    outs=conn.openOutputStream();
    } catch(IOException e) { }
    }
    public void pauseApp() { }
    public void destroyApp(boolean unconditional) { }
    public void commandAction(Command c, Displayable s) {
    if(c==sendCmd) {
    try {
    outs.write((text.getString()+"\n").getBytes());
    } catch(IOException e) {}
    } else { }
    }
    }

    server code

//this receives the socket request from client

    class TCPServer
    {
       public static void main(String argv[]) throws Exception
          {
             try {
                ServerSocket server = new ServerSocket(80);
        System.out.println("ip address : "+InetAddress.getLocalHost());         
        System.out.println("waiting for connection");               
        Socket s1 = server.accept();
        System.out.println("connection established");
        BufferedReader br = new BufferedReader(new
InputStreamReader(s1.getInputStream()));    
            while (true) {
                String str1 = br.readLine();
            System.out.println("client says :" +str1);              
                if (str1.equals("quit"))
                        break;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
          }
    }

//after running this code i m getting a java security exception in my nokia phone any other port no is no responding in the nokia phone

Was it helpful?

Solution

the problem happened because Nokia was blocking the 80 port no for some of its system application so changing of port no along with public ip address did the trick

OTHER TIPS

You should add the public IP of the server in your client code ex.

(SocketConnection)Connection.open( "socket://105.225.251.58" + ":" + "port" );

Note that to use privileged ports like 80, 443, 8080 and generally anything below 1000, you need a code signing certificate(e.g from Thawte) for a real phone.

Otherwise, still to higher un-privileged ports likes 8000 etc

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top