Solved

WinSock programming in MFC (TCP)

Posted on 1998-12-28
1
990 Views
Last Modified: 2013-11-20
How do i create a WinSocket, how do i use it?. I want to make a client program that sends a network message to a server program. Please help me!!
0
Comment
Question by:byrdal
[X]
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
1 Comment
 
LVL 1

Accepted Solution

by:
perrizo earned 150 total points
ID: 1326845
If you know what port the other program listens on and you know what kind of data you need to send it all you have to do is use CAsyncSocket::Send(const void* lpBuf, int nBufLen, int nFlags=0)
to send the data.  Below is a code snipet of what it might look like...

void SomeFunction()
{
   CAsyncSocket* pClientSocket = new CAsyncSocket; // allocate a new socket
   CObject object;
   long timeout = 0;
   CString strReturn;

   pClientSocket->Create(); // create the socket
   pClientSocket->Connect("172.16.128.10", "700"); //ip address and port
   if(pClientSocket->Send(&object, sizeof(object)) != SOCKET_ERROR)  // send the data
   {
      while(pSocket->Receive(&strReturn, sizeof(strReturn), MSG_PEEK) == SOCKET_ERROR && timeout < 5000)  // peek at the socket data for the return message or until timeout
         timeout++

      pSocket->Receive(&strReturn, sizeof(strReturn)); // get the data that just arrived
   }
}

Something like this should work...
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

729 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