Search code examples
javasocketsjava-menokia-s40

socket connection works good on emulator but can't send in real device(j2me)


I am developing a server/client application .The application works fine on an emulator but when I test it on a Nokia 5200 or a Nokia 6303i, although the connection establishes successfully, the server blocks on first read method. In other words, the client(j2me) application can't send data to server.

My client part:

        Thread occ=new Thread(new Runnable() {

                    public void run() {
                        try {
                            SocketConnection sc = (SocketConnection)Connector.open("socket://213.233.169.142:2000");
                            sc.setSocketOption(SocketConnection.DELAY, 0);
                            OutputStream os=sc.openDataOutputStream();
                            DataOutputStream dos=new DataOutputStream(os);

                            InputStream is=sc.openDataInputStream();
                            DataInputStream dis=new DataInputStream(is);

        //dos.writeUTF(receiverT.getString());


        os.write("saalam".getBytes());                                                      

        os.flush();


        dos.writeUTF(Midlet.userPhoneNumber);
        dos.flush();



        dos.writeUTF(messT.getString());
        dos.flush();

          while((!dis.readUTF().equals("system-use:code=2")) && false)
        {

        }




        dos.close();
        os.close();
        sc.close();

                        } catch (IOException ex) {
                            ex.printStackTrace();
                        }
                    }
                });  

        occ.start();

My server part:

 serverSocket = new ServerSocket(2000);
 Socket socket=serverSocket.accept();
 System.out.println("connection stablished");
 inp=new DataInputStream(mySocket.getInputStream());
 outp=new DataOutputStream(mySocket.getOutputStream());

 receiverTemp=inp.read();//the server code blocks on this line

 senderTemp=inp.readUTF();
 .
 .
 .
 .

Solution

  • The problem finally solved.the problem was that some mobile operators don't allow send/receive information with raw sockets so we used HTTP sockets on port 80 and it worked.