is there an example of how to create a thread in a winsock application listenning for incoming connections, while there is still the main thread working with the display of the data received...(basically a chat program)?
thanks in advance
Amon Ra
Printable View
is there an example of how to create a thread in a winsock application listenning for incoming connections, while there is still the main thread working with the display of the data received...(basically a chat program)?
thanks in advance
Amon Ra
could i just get a link to a good tutorial on threads? thanks
Set your project settings to Multithreading.
Code:
#inlcude <windows.h>
#include <process.h>
static void theadFunction (void *arguments) {
// Do Data Retrieval
_endthread();
}
void main (void) {
unsigned long threadID = _beginthread(threadFunction, 0, (void *)0);
if (threadID == -1) {
//Error
}
// Do Display
}
would it just be the same for a windows program?
That is a Windows program ;)
Apart from the different entry point, of course :D
yea, i know..lol..i was just talking about programs with WinMain and WndProc..but ok..thanks :)
It doesn't matter. It's still the same.
Don't call _endthread, just return from the function.
And if you want to do anything with the thread handle (like for eaxmple get the exit code of the thread) or do something advanced (start the thread suspended so you can adjust it's priority) you should use _beginthreadex.
If you don't use any runtime library functions, use CreateThread, it will save you resources.