Re: [twsocket] Send and Shutdown oddity
Hello, either I have implemented the suggestion of confirming the reception of my shutdowncommand and only then closing the connection completely false or it's something quite curious and different: I found out now that the problem only happens under these conditions: - in my application's setup wizard there's the possibility to search for our Bluetooth devices and automatically pair and set them up. - when I close the wizard mentioned shutdowncommand has to be sent so that some part of my app. quits and is restarted afterwards. - only in the case when my app is running on a Laptop with Toshiba Bluetooth stack equipped and the device to be added to my application is not yet paired the shutdown command never arrives, no matter what I do. If the device has been paired previously everythign works like a charm! I've now contacted the developer of our Bluetooth library (named WCL) and hope he might shed some more light on this matter. I'm clueless now. Greetings markus -- 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] Send and Shutdown oddity
what does the event OnSentData _exactly_ signal? Well, there is no such event. You have OnDataSent and OnSendData which are close. OnDataSent: This is when Winsock has accepted all data from TWSocket, that is when TWSocket buffer is emptyed. OnSendData: This is when TWSocket is able to write data to winsock. Does it really signal that WinSock has completed sending the data? There is no such event available. And even if it is, then this doesn't mean anything since the remote side still has to acknowledge it. There could be an event for that, but as far as I know TCP stack doesn't propagate this to the application. I'd like to encourage those who already have a wiki account but never wrote anything in it to start helping to document ICS! +1 -- francois.pie...@overbyte.be The author of the freeware multi-tier middleware MidWare The author of the freeware Internet Component Suite (ICS) 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] Send and Shutdown oddity
Markus Humm wrote: > Hello, > > what does the event OnSentData _exactly_ signal? There does not exist such an event. There are two similar named events, OnDataSent and OnSendData. OnDataSent triggers after ALL data buffered in TWSocket's internal send buffer has been actually sent by winsock API send(). And there is OnSendData that triggers whenever data has been sent by winsock API send(). Whenever you call one of TWSocket's send-methods data is copied to TWSocket's send buffer first and the component the sends it asynchronously in the background. > Does it really signal that WinSock has completed sending the data? No, see above. Winsock does not provide such a callback or event. -- 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
[twsocket] Send and Shutdown oddity
Hello, what does the event OnSentData _exactly_ signal? Does it really signal that WinSock has completed sending the data? Because in my investigations about my problem yesterday I could see that this event always fires on my sending side and reports the correct number of bytes I have sent. But in most cases nothing is received on the receiver side. Unfortunatelly the documentation is weak about details, as there are many Wiki accounts now but only few ever edited something in the wiki. Why do they request an account and then don't use it? I'd like to encourage those who already have a wiki account but never wrote anything in it to start helping to document ICS! Greetings Markus -- 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] Send and Shutdown oddity
Arno Garrels wrote: > Markus Humm wrote: > > I mean if a message loop of 3 sec. doesn't give him enough time >>> Possibly the message loop isn't implemented properly? >>> Please show us some code. >> >> Ok, my message loop was constructed like this: >> >> var msg:TMessage; >>t:Dword; >> >> begin >> t:=GetTickCount; >> while (abs(GetTickCount-t) < 3000) do >> begin >>PeekMessage(msg, 0, 0, 0, pm_remove); >>TranslateMessage(msg); >>DispatchMessage(msg); >>sleep(20); >> end; >> end; > > That's most likely the cause, looks like an attempt to > workaround the async nature of ICS. A message loop should > use GetMessage and no Sleep(). And the loop should be terminated dynamically when it is no longer needed by posting a message i.e. the WM_QUIT message. If something blocks while in that loop 3 seconds might not be enough. It's also burning CPU cycles for nothingh since with every sleep a thread-switch is enforced. -- 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] Send and Shutdown oddity
Markus Humm wrote: I mean if a message loop of 3 sec. doesn't give him enough time >> Possibly the message loop isn't implemented properly? >> Please show us some code. > > Ok, my message loop was constructed like this: > > var msg:TMessage; >t:Dword; > > begin > t:=GetTickCount; > while (abs(GetTickCount-t) < 3000) do > begin >PeekMessage(msg, 0, 0, 0, pm_remove); >TranslateMessage(msg); >DispatchMessage(msg); >sleep(20); > end; > end; That's most likely the cause, looks like an attempt to workaround the async nature of ICS. A message loop should use GetMessage and no Sleep(). -- 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] Send and Shutdown oddity
> Markus Humm wrote: >> > Markus Humm wrote: >>> My application now has to tell the communication part (means the >>> server side of the TWSocket connection) to shut down. it sends him a >>> binary shutdown command and after a short time the client does a >>> shutdown(1) on the socket. >>> >> >>> >> There's most likely something wrong in your application logic. >>> >> When the server receives your custom shutdown command it should stop >>> >> listening first, send an OK-response back to the requesting client >>> >> and disconnect all client connections. >>> >> >>> >> On the client-side after sending your custom shutdown command, >>> >> receive the OK response and subsequently either Close the connection >>> >> actively or wait for the server to close the connection. However with >>> >> "wait" I do of course _not_ mean "wait in some loop", OnSessionClosed >>> >> fire on connection close. >>> >> >> > >> > That might be a option, but I'm not yet fully convinced. How long may >> > it take to send a short message to localhost and receive it on the >> > other side? > It depends. If blocking tasks are executed at that moment no window > messages can be processed and no data can be received. If server and > client are running in the same thread context one blocking task is > enough to block both client and server I/O. > >> > >> > I mean if a message loop of 3 sec. doesn't give him enough time > Possibly the message loop isn't implemented properly? > Please show us some code. Ok, my message loop was constructed like this: var msg:TMessage; t:Dword; begin t:=GetTickCount; while (abs(GetTickCount-t) < 3000) do begin PeekMessage(msg, 0, 0, 0, pm_remove); TranslateMessage(msg); DispatchMessage(msg); sleep(20); end; end; One thing I'm currently not sure of (will check tomorrow) whether the sending application also had its own thread for the TWSocket. If yes, then the waiting was in the main thread instead of the secondary thread. The message processing of the secondary thread would have been implemented with GetMessage then (at least out of my head). I'll check tomorrow. Greetings Markus -- 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] Send and Shutdown oddity
Markus Humm wrote: > Markus Humm wrote: >>> My application now has to tell the communication part (means the >>> server side of the TWSocket connection) to shut down. it sends him a >>> binary shutdown command and after a short time the client does a >>> shutdown(1) on the socket. >> >> There's most likely something wrong in your application logic. >> When the server receives your custom shutdown command it should stop >> listening first, send an OK-response back to the requesting client >> and disconnect all client connections. >> >> On the client-side after sending your custom shutdown command, >> receive the OK response and subsequently either Close the connection >> actively or wait for the server to close the connection. However with >> "wait" I do of course _not_ mean "wait in some loop", OnSessionClosed >> fire on connection close. >> > > That might be a option, but I'm not yet fully convinced. How long may > it take to send a short message to localhost and receive it on the > other side? It depends. If blocking tasks are executed at that moment no window messages can be processed and no data can be received. If server and client are running in the same thread context one blocking task is enough to block both client and server I/O. > > I mean if a message loop of 3 sec. doesn't give him enough time Possibly the message loop isn't implemented properly? Please show us some code. > why should the change of logic be better? Dunno, it's just how I would do it, following a simple request/response pattern. -- 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] Send and Shutdown oddity
Another related question: are there two logical channels in the background of TCP, one for sending the actual data and one for signalling the close? Otherwise I cannot explain myself why the data doesn't arrive but the close does. There is only one channel. Actual data and signalling are using the same physical medium and are using the same packets. There are a number of headers in the packets which makes the distinction. -- francois.pie...@overbyte.be The author of the freeware multi-tier middleware MidWare The author of the freeware Internet Component Suite (ICS) 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] Send and Shutdown oddity
Markus Humm wrote: > > My application now has to tell the communication part (means the > > server side of the TWSocket connection) to shut down. it sends him a > > binary shutdown command and after a short time the client does a > > shutdown(1) on the socket. > > There's most likely something wrong in your application logic. > When the server receives your custom shutdown command it should stop > listening first, send an OK-response back to the requesting client and > disconnect all client connections. > > On the client-side after sending your custom shutdown command, > receive the OK response and subsequently either Close the connection > actively or wait for the server to close the connection. However with > "wait" I do of course _not_ mean "wait in some loop", OnSessionClosed > fire on connection close. > That might be a option, but I'm not yet fully convinced. How long may it take to send a short message to localhost and receive it on the other side? I mean if a message loop of 3 sec. doesn't give him enough time why should the change of logic be better? Another related question: are there two logical channels in the background of TCP, one for sending the actual data and one for signalling the close? Otherwise I cannot explain myself why the data doesn't arrive but the close does. Greetings Markus -- 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] Send and Shutdown oddity
Markus Humm wrote: > My application now has to tell the communication part (means the > server side of the TWSocket connection) to shut down. it sends him a > binary shutdown command and after a short time the client does a > shutdown(1) on the socket. There's most likely something wrong in your application logic. When the server receives your custom shutdown command it should stop listening first, send an OK-response back to the requesting client and disconnect all client connections. On the client-side after sending your custom shutdown command, receive the OK response and subsequently either Close the connection actively or wait for the server to close the connection. However with "wait" I do of course _not_ mean "wait in some loop", OnSessionClosed fire on connection close. -- 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
[twsocket] Send and Shutdown oddity
Hello, I'm using TSWocket and have the following problem: One client and one server running on the same PC (localhost, 127.0.0.1) use the socket as medium to transport commands. It normally works as it should but under certain conditions it fails like this: my application has to deal with Bluetooth as well and in my special case here the Toshiba Bluetooth stack. I can detect the remote device, pair it etc. and then my setup wizard willl be finished by the user clicking a button. My application now has to tell the communication part (means the server side of the TWSocket connection) to shut down. it sends him a binary shutdown command and after a short time the client does a shutdown(1) on the socket. The server is bound to a message processing thread and multithreaded is set to true. Binding is done via ThreadAttach in the execute method of the thread. In the error case the server doesn't receive the shutdown command send by the client, but he eventually gets the closure of the socket. Depennding on ym application logic it sort of hangs in the air then. One thought was that the shutdown(1) call of the client sort of overtakes the send call, but a sleep(1000) directly after the send or a 3 sek long message processing loop directly after the send call didn't help, so I'm no longer really convinced that this short time between those two actions is the cause. On the server side I've hooked into OnChangeState but the only thing this one sees in those cases is the latter wsClosed state. But it fails more often in my perception than it works...and my other perception is, that it only happens when the Toshiba stack is involved, but can't easily check this, as this laptop is the only Toshiba Stack device I own. Greetings Markus -- 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