Solved

WinSock programming in MFC (TCP)

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

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…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

789 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