in reply to Re: tcp server (bidirectional)
in thread tcp server (bidirectional)
Thanks for your help!
Yes, this script will update MySQL database with gps data.
This is great with additional listening socket, but server still needs to receive some data from the client to respond him with a command, right?
I need to be able to send command to connected client without waiting his data.
With your version, old connections still remains opened and does not clean themselves.
When gps device reconnects to the server, it uses a different IP and port No., maybe is this the cause !?
Thanks again!
Igor V.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: tcp server (bidirectional)
by BrowserUk (Patriarch) on Dec 06, 2008 at 21:47 UTC | |
With your version, old connections still remains opened and does not clean themselves. I cannot argue authoratatively with you as I do not have the device is question (nor possibly your OS), but on the basis of logic, that doesn't make much sense. Starting from the point where there is an established connection between the GPS device and the server, under what circumstances would it decide to reconnect? I see two possibilities: When gps device reconnects to the server, it uses a different IP and port No., maybe is this the cause !? Again, I cannot argue with what you are seeing, but logic says this doesn't make sense. If the device connected with a different IP, it would be connecting to a different machine! Unless the server is multi-homed (of which I have no experience), but even so, it would still have to connect to a different (copy of the) server process. And how would it know what other IP to use? I suspect what you are seeing is that when the device reconnects, that the socket handle reported by the print $connection; line in the main accept loop, is different. That's normal! When a new client connects, (even if it is the same client reconnecting), it will get a new IO::Socket::INET instance which will have a different handle to that used previously. Equally, if you are monitoring the port numbers used by the client connections, the server port allocated to the new connection will be different to that used by the listening socket (that's the way tcp works!), and it will often be different to the port number used by the previous client connection, even if it is inbound from the same device and connectiing to the same listening port. Unless you've called shutdown (at both ends, which is unlikely given the possible scenarios ), the previous port number may not get reused (even with Reuse => 1) until both ends of the old connection have either shutdown or timed out. That can take several minutes. This is normal and of no great consequence unless you are re-establishing the same connections 100s of times per second. This is great with additional listening socket, but server still needs to receive some data from the client to respond him with a command, right? Yes. As posted, outbound (server to device) transmissions will not be sent until after an inbound data message (device to server) is received. You cannot (on my system using perl and IO::Socket, at least) transmit to a socket whilst it is currently in a read state. It may be possible on other systems, but no one has ever answered my frequent questions on this to either confirm or deny that possibility. I therefore assume that it is not possible, My assumption (given an absence of information to the contrary), was that the device uploads data packets at regular intervals, and so the longest delay between initiating a command input and it being transmitted, is the length of time between those regular data packets. If this would present an unacceptable delay, there are two possibilities: There is a third possibility. That of setting the socket non-blocking and not using select, but I'm uncomfortable to suggest this as my own experience of trying this have had mixed results. (I make no claims to any great expertise in tcp. I tend to just stick to whatever works for me on my platform. YMMV.) Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] [select] |