Wait time in a socket connection
Posted by kinshuk_mishra (kinshuk_mishra), 18 March 2003Hi All,
I am facing one problem related to sockets. Here is the details....
I have 3 machines in which 2 of them i have made as client and one as server. On each client I have opened one socket connection and listening at unique port. On server side also I have opened one uique port and listening to clients.
Now When ever server requires some information from the client it connects to that port and gets the required information on the socket which is open. Presently I am saving the information from the socket(server side) into a file and then reading the file from within my script. I need to change this to a variable since using persistant storage device is creating problems when scripts are running for long time. In this case I have to use 2 TCL shells since one shell uses sockets and waits for the client and other is used to run all my scripts.
The problem in current (File) case is that my server is running in different TCL shell and scripts are running on different TCL shell so i cannot use variables between them.
The idea what I got is that on client side I will open the sockets in vwait loop but on server side I want that server should wait on unique port only when information is requred by the server from clients. I will open the connection when information is required. This will help me in the case that I will have same shell which will wait with open socket and which will run my scripts also. I tried the same with certain combinations but it is not working. If some body has an idea then please let me know. I only want that connection should wait till the time there is some data in the socket and after that it should return back to the scripts.
Posted by admin (Graham Ellis), 19 March 2003I think this is a continuation of the previous application you have been posting about - you're running on a Windows box, expect (so Tcl 8.0) in the clients, and a more recent version for the server?
I would tend to pass the information across the socket connection rather than using a file; with a file, you'll have all sorts of problems if information is being written by one process while it's being read by another unless you write a sophisticated locking protocol on the socket - and there's no point in doing that when you can simply pass the information across.
I'm a little nervous that you describe your clients as listening (only a server listens in the technical sense), and that you describe vwait as a loop which it really isn't. Do you by any chance have a copy of "Practical Programming in Tcl and Tk"? The third edition has an excellent section on socket programming, and the topics you're asking about are covered on pages 227 to 230. See
In brief, I think that your main server program needs to be a loop which listens for and accepts connections, putting each connection into a vwait on a different variable (use an array of variables?).
Posted by kinshuk_mishra (kinshuk_mishra), 19 March 2003Hi Ellis,
First of all thank you very much for the hint. Actually the hint you gave me in your reply helped me a lot and I was able to integrate my connection into one shell.
This is what I did...
Now using the three machines, I configured 2 of the machines as servers and opened one port on which these machines were listening to the clients...
Third machine which is the main machine and which does most of the processing is now client and whenever I requre some thing from the servers I simply send the request on the port and servers revert back on the same socket connection. This is what I wanted. Now after sending the request to the server I am waiting on that particular socket to get the reply and whenevr I get the reply I close the socket.
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: firstname.lastname@example.org • WEB: http://www.wellho.net • SKYPE: wellho