mfc >> How to use CSocket & Serialize in multithread network program?

by Daric » Fri, 28 Nov 2003 12:08:11 GMT

Hi, all
I'm writing a multithread program to transfer object
data, I want to use CSocket & CSocketFile to serialize
objects over network.
On the server, I start a listening socket in main thread,
when OnAccept() occurs, the main thread will create a sub
thread that with a CSocket member, and the CSocket member
will be accepted in main thread.
I think the sub thread will take charge with the
serialization of data before, but now it seems that the
serialize code is run in the main thread, when
serializing, the main thread can't accept new connection.
How to use CSocket & Serialize in multithread network
program?
Should I create listening socket in every sub thread?
Is it possible to make multithreads serialize data
through a same port at the same time?
Any comment is very appreciated!

My code:
void CDataServer::OnAccept(int nErrorCode)
{
.....
CServerThread* pThread = new CServerThread ();
if(pThread != NULL)
{
Accept(*(pThread->m_pSocket));
....
}
.....
}



mfc >> How to use CSocket & Serialize in multithread network program?

by Scott McPhillips [MVP] » Fri, 28 Nov 2003 18:32:28 GMT






Are you calling Detach and Attach? If you don't use these the socket
runs in the thread it was created in. There is an MFC sample that shows
how to use Detach and Attach.

--
Scott McPhillips [VC++ MVP]




mfc >> How to use CSocket & Serialize in multithread network program?

by Daric » Sat, 29 Nov 2003 11:22:44 GMT

Pass it, thank you very much!


thread,
sub
member
the
connection.
these the socket
sample that shows


Similar Threads

1. MFC CSocket, CArchive and Serializing stop FD_READ Notification VC

2. CArchive::Serialize with CSocket is taking forever to return

Hi All,

I have a CArchive that seem to lock up from time to time and I was hopping 
someone could help me.

When I call "Serialize" it sometimes takes over 40 seconds to return.
All I am doing is getting data received from the socket.

I do have some child threads running but really can't see where/ how they 
could block the execution of the main thread.

Bellow is a portion of the code. Can someone see why the Serialize call 
would lock up?

Is there a tool to help me see what thread is currently working. Maybe it 
would help me to find what I am doing wrong.

///////////////////////////////////////////////
CSocketFile file( m_pMySocket  );
CArchive arIn(&file, CArchive::load);

CSomeClass msg
msg.Serialize(arIn,  m_pMySocket);

msg.Serialize(arIn,  m_pMySocket ); //    <<--- sometimes takes over 40 
seconds to return

///////////////////////////////////////////////
void CSomeClass::Serialize(CArchive& ar)
{
CObject::Serialize(ar);
 if (ar.IsStoring())
 {
  ar << m_sName;    //CString(..)
  ar << m_uType;    //UINT
 }
 else
 {
  ar >> m_sName;    //CString(..)
  ar >> m_uType;    //UINT
 }
}

Many thanks in Advance

Simon 


3. Looking for books / references for Network programming using mutlithreading - CSharp/C#

4. [ace-users] C++ Network Programming: Mastering Complexity Using ACE and Patterns

5. Multithread (MT) vs. Multithread DLL (MD) option

6. Multithread or Multithread DLL?

Hello,

I'm trying to create a worker thread for my VC++ program, and was
wondering whether I should be linking with the Multithread /MT or
Multithread DLL /MD option?  I'm not quite sure, in layman's terms,
what the difference is.

When I build with Multithread DLL, the linker complains about not
being able to find a bunch of "unresolved external symbols" associated
with nafxcwd.lib.

When I build with Multithread, it completes, but when I run, I'm
getting a "Debug Assertion Failed!" error message, associated with
thrdcore.cpp.

Any insight/help appreciated.

Robert

( modify address for return mail )

www.numbersusa.com
www.americanpatrol.com

7. change library from not-multithread to multithread RAD Studio 2007 - C++ Builder IDE

8. c# networking - data sent across network with tcpclient class using rjindael encryption truncates