Hello Pete,

> if myclient.state <> wsConnected then
> begin
>     myclient.connect;
>     loop for 5 seconds begin

You have to think async. TWSocket uses events. think on events as a
OnClick event of a butten. You don't write loops to wait until a user
click a button. So you have to change to:

   MyClient.Connect; // that's all

and in the OnSessionAvailable event you start do
   TWSocket(Sender).sendstr(thedatastring);

>        myclient.processMessages;

General a very bad idea to call the message pump yourself.

> myclient.close();

If your client has send all the data then you still dont know if the
other end has received an handled the data. if you design your proto
yourself then the receiver can close. if  you dont then call
ShutDown(1);

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

Better to use TWSocketSer4ver.

---
Rgds, Wilfried [TeamICS]
http://www.overbyte.be/eng/overbyte/teamics.html
http://www.mestdagh.biz

Monday, November 26, 2007, 18:58, Pete Williams wrote:

> 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