C language > Beginner questions
Non-blocking Sockets
Freddy:
Hi!
Can anyone post an example on how to create simple server using Winsock, that do not block the GUI while it's listening for connections?
Thanks
frankie:
Non blocking call is annoying to program, why don't use a dirrent approach: create a new thread and make the call in this thread so only it will get blocked while the principal thread continues to run. In this way you can define the mechanism which tells you that a data packet is available.
Freddy:
Yes, it seems creating a thread is a better option.
Thanks for the idea.
So, I would use _beginthread() and link with Pelles C multithread library (/MT option), right?
frankie:
Right.
You can also use the win32 API call CreateThread
--- Code: ---HANDLE CreateThread(
LPSECURITY_ATTRIBUTES lpThreadAttributes, // pointer to thread security attributes
DWORD dwStackSize, // initial thread stack size, in bytes
LPTHREAD_START_ROUTINE lpStartAddress, // pointer to thread function
LPVOID lpParameter, // argument for new thread
DWORD dwCreationFlags, // creation flags
LPDWORD lpThreadId // pointer to returned thread identifier
);
--- End code ---
Freddy:
OK. Thanks!
What's the best way to send a file with sockets?
I know how to use Winsock, but I have no clue how would I send a file checking the size of chunks, etc.
Thanks again.
Navigation
[0] Message Index
[#] Next page
Go to full version