Solved

WinSock programming in MFC (TCP)

Posted on 1998-12-28
1
984 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
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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.

786 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