Hello again

I'm trying to write a very simple client/server socket application using 
TWSocket. However, I think I may not understand the use of states correctly.

What I want is for the client to connect to the server, send some data, 
and then disconnect. If it has more data to send, I want it to connect 
again and repeat the process.

Here's what is happening at the moment. The client can connect to the 
server and successfully send as much data as it chooses. However, once 
it disconnects it can't reconnect.

The code on the client is broadly thus (using  a pseudo code):

if myclient.state <> wsConnected then
begin
    myclient.connect;
    loop for 5 seconds begin
       myclient.processMessages;
       if myclient.state = wsConnected then
       begin
          lbConnected := TRUE:
          break;
       end;
    end loop;
end else
    lbConnected := TRUE;

if lbConnected then
    myclient.sendstr(thedatastring);

myclient.close();

On the server, this is what I have:

myserver.OnsessionAvailable
begin
    myserversocket.dup(myserversocket.accept());
end;

I'm also handling the OnDataAvailable event, and this works fine - but 
only the first time (or at least until the client disconnects).

I've tried recalling listen() in the OnSessionClosed event, but it does 
nothing.

The state of the client on the 2nd attempt to reconnect remains at closed.

If anyone can point me in the right direction I'd be grateful. Maybe I 
need some form of clean-up on the server after the disconnect?

Cheers,
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to