Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


CSocket and CSocketFile

Posted on 2000-03-07
Medium Priority
Last Modified: 2013-11-20
I am trying to make  a simple client server application using CSocket and CSocketFile.
I have coded 2 thread functions, one listens for clients requests, while after moving beyond Accept()... first thread funtion "ServerStarter" is supposed to spin the other thread whoise function is "ClientHandler".
Code is as under
UINT ServerStarter(LPVOID pParam)
{CClientSocket*      clientsocket = new CClientSocket();
CListenSocket*      listensocket = new CListenSocket();
CWinThread *def = AfxBeginThread(ClientHandler,clientsocket,THREAD_PRIORITY_BELOW_NORMAL,CREATE_SUSPENDED);
and "ClientHandler" is as under
UINT ClientHandler(LPVOID pParam)

CString test = " hello server here";
      return 0;

while init() is as under

void CClientSocket::init()

pSocketFile = new CSocketFile(this);
in = new CArchive(pSocketFile,CArchive::store);
out= new CArchive(pSocketFile,CArchive::load);


now programme give an "Assert_Valid" when it goes inside the init on the line
in = ........
to me, it seems that that socket is appearing an unvalid one to it. But if I dont start the thread "ClientHandler" and try to send to the data to client from first thread "ServerHandler" every things goes ok.
what could be the reason ?
Question by:daknight2000
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Author Comment

ID: 2593942
I have also tried making "clientsocket" as a global variable  but it didnt help.

Accepted Solution

ShaunWilde earned 400 total points
ID: 2594627
You should only use CSockets etc in a CWinThread (UI thread) type thread as the CWinThread contains all the initialization required to manage CSockets.

so in your OnAccept of your listener socket you would (pseudo code)

CSocket tempSocket;





then you would attach your socket to your thread in the initinstance
class CSocketThread:public CWinThread
SOCKET tempHandle;
CClientSocket m_socket; // derived from CSocket




Author Comment

ID: 2607522
sorry i was busy i got late

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question