Many connections to a single TCP port of EHS5 module | Telit Cinterion IoT Developer Community
January 29, 2020 - 8:54am, 1637 views
Hello,
I use EHS5 modules Rev 03 and Rev 04 with my Java application inside.
My Java application opens a TCP socket connection in Server mode (so that a TCP-client could connect to the module).
There is a problem with multiple connections to the same TCP-port. When someone connects to my module, I can't connect to it (because EHS5 module can establish only one connection for the TCP-port in TCP server mode). But how to understand that TCP connection has already been established?
I have 3 questions:
1) Is it posible to get some internal notifications from Java in EHS5 module that another client is connecting to the same TCP-port?
2) Is it possible to reject other connections if one connection is already established?
3) Is it possible to process and setup multiple connections with the same TCP-port of EHS5 module?
Thank you for answers.
Regards,
Vitaliy
Hello Vitaliy,
The port that the server connection listens on is only used for listening. When the conneciton is established the local port for this connection is being assigned automatically from a pool. You can also check this port number with Java API.
So it is all about how your Java MIDlet is designed. You should start a new thread for each connection and the main listening thread should go back to listening again. Then the app shouls be able to open more than one incomming connection.
Before the listening thread goes back to listenign again by calling the blocking method acceptAndOpen() all the incomming connections will be rejected.
Regards,
Bartłomiej
Hello,
You wrote:
"Before the listening thread goes back to listenign again by calling the blocking method acceptAndOpen() all the incomming connections will be rejected."
But I can easily connect to the same port by Hyperterminal software. acceptAndOpen() is not calling at the moment. I think you can see the same behavior if you will have one thread calling acceptAndOpen() and then make some connect-disconnect actions from a client to the port.
My task is to reject all connections accept the first one. Should I repeatedly call acceptAndOpen() and close all other connections if the only one has been established?
Thank you for your answers.
BR,
Vitaliy
Hello,
My point was that only by calling acceptAndOpen() method your application may be informed about an incoming connection - and the connection is being open automatically. After being open it can be closed by the application.
If listening is no longer necessary the app may not call acceptAndOpen() again and close the server socket connection. The other incoming connections are not being open on the module side if acceptAndOpen() was not called before. To see what exactly is happening on the TCP layer we'd have to trace the TCP traffic (if the module sends some reject or just ignores such a connection attempt).
Regards,
Bartłomiej