Re: [twsocket] I need some help understanding TWsocket states
[EMAIL PROTECTED] wrote: > Its nice to have a mailing list where you can get > many people addressing the same questions :) Agreed, and don't forget the free sources. Do you realy need more? -- Arno Garrels -- 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
Re: [twsocket] I need some help understanding TWsocket states
Pablo, Are you having more problems? P.S. Puedes comunicarte conmigo directamente si necesitas ayuda en espaƱol. Translation: You can contact me directly if you require help in Spanish. -dZ. >--- Original Message --- >From: Pablo Harguindey[mailto:[EMAIL PROTECTED] >Sent: 11/28/2007 3:22:18 PM >To : twsocket@elists.org >Cc : >Subject : RE: Re: [twsocket] I need some help understanding TWsocket states > >*help -- 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
Re: [twsocket] I need some help understanding TWsocket states
>--- Original Message --- >From: Arno Garrels[mailto:[EMAIL PROTECTED] > > OnSessionAvailable is called only on listening TWSockets, > as I read the post it deals with a client (connecting party). Thanks, Arno. You are right; I misread his message but didn't realize this after sending my response. I then explained the same thing, just like you and Wilfried did, so he's sure to understand it now :) Its nice to have a mailing list where you can get many people addressing the same questions :) -dZ. -- DZ-Jay [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html -- 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
Re: [twsocket] I need some help understanding TWsocket states
*help -Mensaje original- De: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] En nombre de Arno Garrels Enviado el: MiƩrcoles, 28 de Noviembre de 2007 15:37 Para: ICS support mailing Asunto: Re: [twsocket] I need some help understanding TWsocket states [EMAIL PROTECTED] wrote: > Hello: >This may sound stupid, but could you verify that > the OnSessionAvailable event is actually wired > (assigned to the property)? It seems strange that it > is not called, yet OnDataSent is. OnSessionAvailable is called only on listening TWSockets, as I read the post it deals with a client (connecting party). -- Arno Garrels > >Also, what happens when you try to send a second > time (or does it even try)? Do you get a "Component > already connected" error or something like that? > >If your burst messages are short as your example > implies, then there is really no reason to do this on > a separate thread; it will actually be slower to > spawn a new thread and execute it than to just > re-connect and call SendStr. > > -dZ. > > >> --- Original Message --- >>> From: Pete Williams[mailto:[EMAIL PROTECTED] >> Sent: 11/28/2007 1:49:27 PM >> To : twsocket@elists.org >> Cc : >> Subject : RE: Re: [twsocket] I need some help understanding TWsocket >> states >> > >Thank you to the two people who replied. I got > really good advice which > I followed and this seems to have given me a working > server, but I still > have client problems. > > - I created a message-pump in a distinct thread for > the DLL server, as > advised. > - Both client and server were changed to async > programming style, and > this worked for the server. > > I have another problem though, which seems stange, > and may be related to > timing (or something). > > My client wants to sometimes connect to the server, > send a few lines of > data, and then disconnect. > > When I want to send data this is what I do > > procedure sendData(asMessage: string); > begin > mystringlist.add(asMessage); > if mytwsocket.state <> wsConnected then > begin >mytwsocket.addr := '127.0.0.1'; // client and > server are on same > machine >mytwsocket.port := '17072'; >mytwsocket.connect(); > end; > end; > > Then I have handlers for OnSessionAvailable and > OnDataSent. > OnSessionAvailable doesn't seem to get called ever. > > In OnDataSent I do this > > begin > if mystringlist.count > 0 then > begin >mytwsocket.sendStr(mystringlist[0]+#$D#$A); >mystringlist.delete(0); // we've sent this one > end else > begin >mytwsocket.close(); // no more data to send, > so close > end; > end; > > Here's what I've observed. The client can send once, > and that's it. I > can't send twice. However, if I put a breakpoint at > the end of the > function that connects to the server,it works - > almost like there is > some kind of timing issue. > > I'm working on Windows 2003. > > Should I use threads for my clients as well? Any > advice is greatly received. > > > Wilfried Mestdagh wrote: >> 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 >> >> Mo
Re: [twsocket] I need some help understanding TWsocket states
Wilfried you are a total star. If you are ever in Edinburgh I'll buy you a cake (or a whisky) or whatever. That works! Wilfried Mestdagh wrote: > Hello Pete, > > >>mytwsocket.addr := '127.0.0.1'; >>mytwsocket.port := '17072'; >>mytwsocket.connect(); >> > > that's ok > > >> OnSessionAvailable doesn't seem to get called ever. >> > > No you need OnSessionConnected. OnSessionAvailable is for server > sockets. > > >> In OnDataSent I do this >> > > >> begin >> if mystringlist.count > 0 then >> begin >>mytwsocket.sendStr(mystringlist[0]+#$D#$A); >>mystringlist.delete(0); // we've sent this one >> end else >> begin >>mytwsocket.close(); // no more data to send, so close >> end; >> end; >> > > Not good. you close in OnDataSent. OnDataSent is fired when data is > deliverd to winsock. This does not mean it is delivered to the other end > of the connection. Instead of Close() call ShutDown(1); This will tell > the other end to shutdown after data is delivered. > > but still it is better to make a little protocol so that receiver tell > sender that all data is delivered and handled and it is safe to close. > > >> Should I use threads for my clients as well? >> > > No need to use threading model. you only need threads if you have > lengthy code. > > --- > Rgds, Wilfried [TeamICS] > http://www.overbyte.be/eng/overbyte/teamics.html > http://www.mestdagh.biz > > -- 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
Re: [twsocket] I need some help understanding TWsocket states
[EMAIL PROTECTED] wrote: > Hello: >This may sound stupid, but could you verify that > the OnSessionAvailable event is actually wired > (assigned to the property)? It seems strange that it > is not called, yet OnDataSent is. OnSessionAvailable is called only on listening TWSockets, as I read the post it deals with a client (connecting party). -- Arno Garrels > >Also, what happens when you try to send a second > time (or does it even try)? Do you get a "Component > already connected" error or something like that? > >If your burst messages are short as your example > implies, then there is really no reason to do this on > a separate thread; it will actually be slower to > spawn a new thread and execute it than to just > re-connect and call SendStr. > > -dZ. > > >> --- Original Message --- >>> From: Pete Williams[mailto:[EMAIL PROTECTED] >> Sent: 11/28/2007 1:49:27 PM >> To : twsocket@elists.org >> Cc : >> Subject : RE: Re: [twsocket] I need some help understanding TWsocket >> states >> > >Thank you to the two people who replied. I got > really good advice which > I followed and this seems to have given me a working > server, but I still > have client problems. > > - I created a message-pump in a distinct thread for > the DLL server, as > advised. > - Both client and server were changed to async > programming style, and > this worked for the server. > > I have another problem though, which seems stange, > and may be related to > timing (or something). > > My client wants to sometimes connect to the server, > send a few lines of > data, and then disconnect. > > When I want to send data this is what I do > > procedure sendData(asMessage: string); > begin > mystringlist.add(asMessage); > if mytwsocket.state <> wsConnected then > begin >mytwsocket.addr := '127.0.0.1'; // client and > server are on same > machine >mytwsocket.port := '17072'; >mytwsocket.connect(); > end; > end; > > Then I have handlers for OnSessionAvailable and > OnDataSent. > OnSessionAvailable doesn't seem to get called ever. > > In OnDataSent I do this > > begin > if mystringlist.count > 0 then > begin >mytwsocket.sendStr(mystringlist[0]+#$D#$A); >mystringlist.delete(0); // we've sent this one > end else > begin >mytwsocket.close(); // no more data to send, > so close > end; > end; > > Here's what I've observed. The client can send once, > and that's it. I > can't send twice. However, if I put a breakpoint at > the end of the > function that connects to the server,it works - > almost like there is > some kind of timing issue. > > I'm working on Windows 2003. > > Should I use threads for my clients as well? Any > advice is greatly received. > > > Wilfried Mestdagh wrote: >> 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 thin
Re: [twsocket] I need some help understanding TWsocket states
Pete Williams wrote: > My client wants to sometimes connect to the server, send a few lines > of data, and then disconnect. > > When I want to send data this is what I do > > procedure sendData(asMessage: string); > begin > mystringlist.add(asMessage); > if mytwsocket.state <> wsConnected then > begin >mytwsocket.addr := '127.0.0.1'; // client and server are on > same machine >mytwsocket.port := '17072'; >mytwsocket.connect(); > end; > end; Next event that fires will be OnSessionConnected. in OnSessionConnected you can safly send data. > > Then I have handlers for OnSessionAvailable Connecting TWSockets will never fire this event, instead assign OnSessionConnected at the client-side. OnSessionAvailable triggers on listening TWSockets only. > and OnDataSent. > OnSessionAvailable doesn't seem to get called ever. OnDataSent is usefull to send large data in smaller chunks. It's always called when the internal send buffer became empty. -- Arno Garrels -- 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
Re: [twsocket] I need some help understanding TWsocket states
Hello: OnSessionAvailable is triggered when an incoming connection is about to be established, as soon as the request is received, but before the socket is properly opened. OnSessionConnected is triggered right after the connection, either incoming or outgoing, is properly established and state is changed to wsConnected. If you're not listening on the port, then that could explain why OnSessioinAvailable is not being triggered. You want to handle OnSessionConnected instead. -dZ. >--- Original Message --- >From: Pete Williams[mailto:[EMAIL PROTECTED] >Sent: 11/28/2007 2:09:51 PM >To : twsocket@elists.org >Cc : >Subject : RE: Re: [twsocket] I need some help understanding TWsocket states > >I don't mind checking simple stuff. I'm desperate, as I have a deadline for Saturday! It is definately connected & hooked-up. Nothing is over-writing it. [EMAIL PROTECTED] wrote: > Hello: >This may sound stupid, but could you verify that > the OnSessionAvailable event is actually wired > (assigned to the property)? It seems strange that it > is not called, yet OnDataSent is. > >Also, what happens when you try to send a second > time (or does it even try)? Do you get a "Component > already connected" error or something like that? > >If your burst messages are short as your example > implies, then there is really no reason to do this on > a separate thread; it will actually be slower to > spawn a new thread and execute it than to just > re-connect and call SendStr. > > -dZ. > > -- 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 -- 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
Re: [twsocket] I need some help understanding TWsocket states
Hello Pete, >mytwsocket.addr := '127.0.0.1'; >mytwsocket.port := '17072'; >mytwsocket.connect(); that's ok > OnSessionAvailable doesn't seem to get called ever. No you need OnSessionConnected. OnSessionAvailable is for server sockets. > In OnDataSent I do this > begin > if mystringlist.count > 0 then > begin >mytwsocket.sendStr(mystringlist[0]+#$D#$A); >mystringlist.delete(0); // we've sent this one > end else > begin >mytwsocket.close(); // no more data to send, so close > end; > end; Not good. you close in OnDataSent. OnDataSent is fired when data is deliverd to winsock. This does not mean it is delivered to the other end of the connection. Instead of Close() call ShutDown(1); This will tell the other end to shutdown after data is delivered. but still it is better to make a little protocol so that receiver tell sender that all data is delivered and handled and it is safe to close. > Should I use threads for my clients as well? No need to use threading model. you only need threads if you have lengthy code. --- Rgds, Wilfried [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html http://www.mestdagh.biz -- 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
Re: [twsocket] I need some help understanding TWsocket states
I don't mind checking simple stuff. I'm desperate, as I have a deadline for Saturday! It is definately connected & hooked-up. Nothing is over-writing it. [EMAIL PROTECTED] wrote: > Hello: >This may sound stupid, but could you verify that > the OnSessionAvailable event is actually wired > (assigned to the property)? It seems strange that it > is not called, yet OnDataSent is. > >Also, what happens when you try to send a second > time (or does it even try)? Do you get a "Component > already connected" error or something like that? > >If your burst messages are short as your example > implies, then there is really no reason to do this on > a separate thread; it will actually be slower to > spawn a new thread and execute it than to just > re-connect and call SendStr. > > -dZ. > > -- 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
Re: [twsocket] I need some help understanding TWsocket states
Hello: This may sound stupid, but could you verify that the OnSessionAvailable event is actually wired (assigned to the property)? It seems strange that it is not called, yet OnDataSent is. Also, what happens when you try to send a second time (or does it even try)? Do you get a "Component already connected" error or something like that? If your burst messages are short as your example implies, then there is really no reason to do this on a separate thread; it will actually be slower to spawn a new thread and execute it than to just re-connect and call SendStr. -dZ. >--- Original Message --- >From: Pete Williams[mailto:[EMAIL PROTECTED] >Sent: 11/28/2007 1:49:27 PM >To : twsocket@elists.org >Cc : >Subject : RE: Re: [twsocket] I need some help understanding TWsocket states > >Thank you to the two people who replied. I got really good advice which I followed and this seems to have given me a working server, but I still have client problems. - I created a message-pump in a distinct thread for the DLL server, as advised. - Both client and server were changed to async programming style, and this worked for the server. I have another problem though, which seems stange, and may be related to timing (or something). My client wants to sometimes connect to the server, send a few lines of data, and then disconnect. When I want to send data this is what I do procedure sendData(asMessage: string); begin mystringlist.add(asMessage); if mytwsocket.state <> wsConnected then begin mytwsocket.addr := '127.0.0.1'; // client and server are on same machine mytwsocket.port := '17072'; mytwsocket.connect(); end; end; Then I have handlers for OnSessionAvailable and OnDataSent. OnSessionAvailable doesn't seem to get called ever. In OnDataSent I do this begin if mystringlist.count > 0 then begin mytwsocket.sendStr(mystringlist[0]+#$D#$A); mystringlist.delete(0); // we've sent this one end else begin mytwsocket.close(); // no more data to send, so close end; end; Here's what I've observed. The client can send once, and that's it. I can't send twice. However, if I put a breakpoint at the end of the function that connects to the server,it works - almost like there is some kind of timing issue. I'm working on Windows 2003. Should I use threads for my clients as well? Any advice is greatly received. Wilfried Mestdagh wrote: > 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
Re: [twsocket] I need some help understanding TWsocket states
Thank you to the two people who replied. I got really good advice which I followed and this seems to have given me a working server, but I still have client problems. - I created a message-pump in a distinct thread for the DLL server, as advised. - Both client and server were changed to async programming style, and this worked for the server. I have another problem though, which seems stange, and may be related to timing (or something). My client wants to sometimes connect to the server, send a few lines of data, and then disconnect. When I want to send data this is what I do procedure sendData(asMessage: string); begin mystringlist.add(asMessage); if mytwsocket.state <> wsConnected then begin mytwsocket.addr := '127.0.0.1'; // client and server are on same machine mytwsocket.port := '17072'; mytwsocket.connect(); end; end; Then I have handlers for OnSessionAvailable and OnDataSent. OnSessionAvailable doesn't seem to get called ever. In OnDataSent I do this begin if mystringlist.count > 0 then begin mytwsocket.sendStr(mystringlist[0]+#$D#$A); mystringlist.delete(0); // we've sent this one end else begin mytwsocket.close(); // no more data to send, so close end; end; Here's what I've observed. The client can send once, and that's it. I can't send twice. However, if I put a breakpoint at the end of the function that connects to the server,it works - almost like there is some kind of timing issue. I'm working on Windows 2003. Should I use threads for my clients as well? Any advice is greatly received. Wilfried Mestdagh wrote: > 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
Re: [twsocket] I need some help understanding TWsocket states
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
Re: [twsocket] I need some help understanding TWsocket states
Hello Pete, The states are not that important, but the events are. Check this link: http://wiki.overbyte.be/wiki/index.php/Asynchronous_Paradigm and ask your questions here if it doesn't answer your question. -- Arno Garrels [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html 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
[twsocket] I need some help understanding TWsocket states
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