Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Dec : Thread, blocking socket
| Subject: | Thread, blocking socket |
| Posted by: | "Richard Carpenter" (richar..@richardj.demon.co.uk) |
| Date: | Sat, 30 Dec 2006 16:21:45 |
Hi all,
I have some code that I have written that *shouldn't* work but it does
beautifully... which obviously concerns me. I'll explain it in pseudocode
but if anyone needs to see the actual code then I'll post that too.
I've created a TThread descendent, its Execute method does one thing and
that is call the "ReadData" private method in a "While not terminated" loop.
So it's
While not terminated do
ReadData;
The ReadData method is as follows;
If (RecvFrom(fSocket, fBuffer[0],1,0,fFrom, size) <> SOCKET_ERROR) then
WriteDataToFile(fBuffer[0])
That's all that's in the ReadData method, very simple and works well. The
socket is a blocking datagram socket set up for broadcasting on UDP.
I also have a public method called SendData(const value:string) in the
TThread that takes a string parameter, creates a new socket and broadcasts
that data across the network then closes the socket.
Now the confusing thing is that when the thread enters the RecvFrom it waits
like a blocking socket should. *If*, however I call the SendData method from
my app the thread jumps out of the RecvFrom, actions the SendData method
then returns back to the RecvFrom to continue waiting for data!
I would have expected the thread to be "locked up" in the RecvFrom until
data arrives but that doesn't appear to be the case. The whole thing works
beautifully in that I can send any string data from my app and still be
receiving data in the RecvFrom function... and I cannot for the life of me
fathom out why this is happening.
I have made sure no timeout is set for the RecvFrom yet it consistently
jumps out and back in again when the SendData method is called.
Can anyone explain why the thread is doing that? Any guidance would be much
appreciated.
Kindest regards and Happy New Year,
Richard