J2ME won't connect to remote socket

161 Views Asked by At

I have a J2ME app that should connect to the socket, launched somewhere. When I run everything at localhost, it all works fine, but if I launch it on my server and try to connect it in the client, it won't connect and it throws an exception:

javax.microedition.io.ConnectionNotFoundException: error 10051 in socket::open
    at com.sun.midp.io.j2me.socket.Protocol.open0(), bci=0
    at com.sun.midp.io.j2me.socket.Protocol.connect(), bci=184
    at com.sun.midp.io.j2me.socket.Protocol.open(), bci=216
    at com.sun.midp.io.j2me.socket.Protocol.openPrim(), bci=4
    at javax.microedition.io.Connector.open(), bci=47
    at javax.microedition.io.Connector.open(), bci=3
    at javax.microedition.io.Connector.open(), bci=2
 - Midlet.startApp(Midlet.java:315)
    at javax.microedition.midlet.MIDletTunnelImpl.callStartApp(), bci=1
    at com.sun.midp.midlet.MIDletPeer.startApp(), bci=5
    at com.sun.midp.midlet.MIDletStateHandler.startSuite(), bci=261
    at com.sun.midp.main.AbstractMIDletSuiteLoader.startSuite(), bci=38
    at com.sun.midp.main.CldcMIDletSuiteLoader.startSuite(), bci=5
    at com.sun.midp.main.AbstractMIDletSuiteLoader.runMIDletSuite(), bci=144
    at com.sun.midp.main.AppIsolateMIDletSuiteLoader.main(), bci=26

And here is the code that should make my app connect to the server:

    SocketConnection sc = (SocketConnection) Connector.open("socket://134.0.118.249:7997");

Also, when I connect to that address via Telnet, everything works fine. What's wrong with my code?

2

There are 2 best solutions below

2
Arpit Asati On

Check your server firewall and allow the traffic through port 7997.

0
Arpit Asati On

I have searched a lot for J2ME socket and get this document, please read it and check if it can resolve your problem of J2ME socket connection.

http://www.inf.unibz.it/~ricci/MS/slides-2010-2011/6-J2ME-NETWORKING-P1.pdf