|
-
May 30th, 2006, 07:47 AM
#1
[RESOLVED] Multithreaded Socket
I'm having some problems moving my socket to a new thread so it can run independently to the rest of my application.
I'm using AsyncSocket and WinThread.
So far I've
instantiated the socket (with connection)
created the new thread (in suspended mode)
copied the socket to the thread
and started the thread...
As far as I can tell its working fine but I cant seem to figure out how to catch the onReceive calls within the new thread.
When the socket was created within the original (Main Thread) it was created from an overloaded socket class (CMySocket) which I defined the behavior for onReceive calls. But it was saved as a CAsyncSocket within the new thread.
So... how do I define the onReceive behaviors etc.
Thanks in advance.
-
May 30th, 2006, 01:08 PM
#2
Re: Multithreaded Socket
For CAsyncSocket, your thread must be a UI thread. See this post: http://www.codeguru.com/forum/showth...34#post1397934
Mike
-
May 30th, 2006, 01:19 PM
#3
Re: Multithreaded Socket
I've gotten that far already.
My Derived Socket class:
CMySocket public : CAsyncSocket{
CSocketThread *thread;
}
My Derived Thread class
CSocketThread : CWinThread{
CAsyncSocket m_pMySocket;
SOCKET m_socket;
}
This is my problem... I attach the socket to my new thread:
CAsyncSocket m_pMySocket;
SOCKET m_socket;
m_pMySocket.Attach(m_socket);
I'm trying to figure out how to define the behaviors of the onReceive() onSend() etc functions for a data member that is the base Class type.
Should I somehow instantiate m_pMySocket to be CMySocket rather than CAsyncSocket?
This threw me errors since CMySocket contains a CSockThread and CSockThread would contain a CMySocket
Or should I just create a dummy class to create and accept the connection then pass it to the thread and have it assigned to a CMySocket type?
Please help.... I dont understand this very well.
-
May 31st, 2006, 12:48 PM
#4
Re: Multithreaded Socket
Nevermind.... I figured it out... I just needed an additional Socket class as a listener.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|