TCP Server connection issues
jellybean
Posts: 8
Can anyone help,
I open a server/port to listen for incomming strings in netlinx studio. This works fine and the port stays open.
I am using a terminal program on my PC to send text strings to the AMX processor. This again works fine.
My problem is if the PC or Terminal program is cut off from the network, (lets say I'm using WiFI and move out of range) and then I regain connection with my network, the server no longer responds to incoming strings.
Whats happing is the terminal can not re-connect to the open port. Netlinx shows no error as if the terminal never disconnected. And therefor i cannot force the server to re-open the port as it hasn't a ctually closed.
If I manually disconect the terminal and reconnect it works perfectly. It's just if you loose the connection by network interuption.
Please help if anyone can understand what i'm trying to explain LOL
I open a server/port to listen for incomming strings in netlinx studio. This works fine and the port stays open.
I am using a terminal program on my PC to send text strings to the AMX processor. This again works fine.
My problem is if the PC or Terminal program is cut off from the network, (lets say I'm using WiFI and move out of range) and then I regain connection with my network, the server no longer responds to incoming strings.
Whats happing is the terminal can not re-connect to the open port. Netlinx shows no error as if the terminal never disconnected. And therefor i cannot force the server to re-open the port as it hasn't a ctually closed.
If I manually disconect the terminal and reconnect it works perfectly. It's just if you loose the connection by network interuption.
Please help if anyone can understand what i'm trying to explain LOL
0
Comments
Judging from the documentation about IP_SERVER_OPEN(LocalPort,ServerPort,Protocol)), any open local port so defined can only sustain one connection at a time. It seems likely that what is happening to you is that the server you are opening thinks that it already has a connection when you try to reconnect. It's not sufficiently clever to see that the connection request is from the same client. I can think of three possible ways to handle this:
1. After a certain time out period with no communication from the client, close the server and re-open it. Lots of servers behave this way.
2. Open multiple local servers (probably just two) with different local ports watching the same server port. Then when you try to reconnect, you will connect to the second local port and you can close and re-open the first local port. If you have an active client connected and a second client connects, the first client would be killed -- don't know if that's a problem.
3. Telnet communications may allow the server to require a response to certain queries. The rules for Telnet communications are on the net. Find a query that the client will respond to and periodically send that query from your active server to the client. If the client fails to respond properly, close and re-open the server. The keep alive dialog may be useable for this--have to experiment to see how your client behaves.
To add to idea #3 if your servers sends a periodic command like "$FF, $FD, $01" which is telnet for "DO ECHO", your PC acting as a client will probably respond in some way, possible "$FF, $FB, $01", "WILL ECHO". For more info look at this thread: http://amxforums.com/showthread.php?t=6856&highlight=telnet+command
You'll have to play and see but it should work and if the Master (server) doesn't receive a response in a pre-dertmine amount of time, presume your PC lost connection so close and then re-open the server.
If the client drops from the network it doesn?t matter to the server. It will just sit there and wait and I don?t ?think? there is a timeout.
UDP (User Datagram Protocol) is often referred to (an wrongly so) as Unreliable Datagram Protocol since there is never a guarantee that a message will arrive at its destination.
But there are cases where UDP a perfect fit and this might be one of them.
UDP is also great for broadcasting. If you send a UDP message to xxx.xxx.xxx.255, everyone on the xxx.xxx.xxx network will receive the message.
Thanks for the prompt response! Fantastic.
Have come to similar conclusions. It's a little undesireable to time out the server, but the alternate port solution sounds good. I'll have to spend some time working out how to code that.
The posibility of asking for a periodic responce from the client is an issue. I'm actually using a Terminal program on an iphone for the final project which does not respond to incoming requests (one way i'm afraid)
The App is called "TCP/IP Remote" by Michael Zinman
I also get the problem when roaming arround the house, i jump from one wifi access point to another. All on the same network but it causes the same problem.
solution no.2 sugested seams like the best way forward. any help with this would be fantastic!!!
Thanks every one again.