Can´t open a socket connection from J2ME to a C# server

761 views Asked by At

I´m trying to open a tcp socket from a j2me midlet on a symbian device to a windows (C#) socket server. The server is working and was tested for months. Now when I try to open a socket from the midlet

clientSocketConnection = (SocketConnection) Connector.open("socket://" + ip + ":" + port);

it just times out with a -34 error (Could not connect).

I know the phone has network capabilities and permissions as I can open such socket connections between 2 phones (emulated) using "ServerSocket" on one side and in the same machine the server is on.

Somehow the J2ME Socket is not compatible with the C# counterpart....

listenSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

Any hint on this matter would be really appreciated. Also, should I use another type of socket on the server side? I could not find information about the AdressFamily, SocketType nor ProtocolType for the J2ME sockets.

Adding info due to the recent comments. It´s not a firewall problem as I have no firewall and DMZ is configured for the machine ip. The phone (emulated) has access to internet and when I open a socket from an emulator to another, both on the same machine, using my WAN PUBLIC ip on the "client" side to find the "server" side it works.

1

There are 1 answers

1
TigerShark On BEST ANSWER

Well it´s solved now. Really weird but binding a j2me listening port (ServerPort) on "localhost" it´s not the same as binding a .net listening port on "localhost". I mean, when I made a "server" midlet listening on localhost the clients could connect, but when I did it on the .net server they couldn´t. The "solution" was to hardcore the computer ip instead of using "localhost". I really do not understand why, but this worked...