Socket ptogramming
-
Hi All, Im implementing socket in my application. its working fine, but my problem is i want to attach a thread for socket receive. how can i implement this, plz help me out... im using CAsyncSocket. its a dialog based application. With Regards Amjath
-
Hi All, Im implementing socket in my application. its working fine, but my problem is i want to attach a thread for socket receive. how can i implement this, plz help me out... im using CAsyncSocket. its a dialog based application. With Regards Amjath
-
Do you mean that you want to pass the socket to a thread for receiving? You can do that by using the thread's parameter and pass the socket variable to it.
First of all thanks for ur reply...... if possible plz help me through some sample code.......... can u plz do this needful help... With regards Amjath
-
First of all thanks for ur reply...... if possible plz help me through some sample code.......... can u plz do this needful help... With regards Amjath
Here's a somewhat sample code to pass the SOCKET to a thread. Hope this helps.
CAsyncSocket ListenSocket; //global socket variable, declare this in the header file BOOL CClassSample::Initialize() { //initialize the pipe variable //create the thread HListenThread = CreateThread(NULL, 0, &ListenThread, (LPVOID)&ListenSocket, 0, &ListenThreadID ); //Error handling for CreateThread if (HListenThread == NULL || HListenThread == INVALID_HANDLE_VALUE) { return FALSE; } } DWORD WINAPI CClassSample::ListenThread(LPVOID lpParameter) { //assign the parameter to the SOCKET variable CAsyncSocket *pListenSocket = (CAsyncSocket*)lpParameter; //some processing here }
-
Here's a somewhat sample code to pass the SOCKET to a thread. Hope this helps.
CAsyncSocket ListenSocket; //global socket variable, declare this in the header file BOOL CClassSample::Initialize() { //initialize the pipe variable //create the thread HListenThread = CreateThread(NULL, 0, &ListenThread, (LPVOID)&ListenSocket, 0, &ListenThreadID ); //Error handling for CreateThread if (HListenThread == NULL || HListenThread == INVALID_HANDLE_VALUE) { return FALSE; } } DWORD WINAPI CClassSample::ListenThread(LPVOID lpParameter) { //assign the parameter to the SOCKET variable CAsyncSocket *pListenSocket = (CAsyncSocket*)lpParameter; //some processing here }
Thank u very much dude im new to vc++, sorry for asking such a small question from where v can get this variable buddy "ListenThreadID"
-
Thank u very much dude im new to vc++, sorry for asking such a small question from where v can get this variable buddy "ListenThreadID"
Amjath Rahman wrote:
im new to vc++,
So why are you trying to tackle a project that is not for beginners? Sockets or threads is a medium-difficulty project at best, but doing them in tandem is no trivial task.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
Thank u very much dude im new to vc++, sorry for asking such a small question from where v can get this variable buddy "ListenThreadID"