Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

WinSock programming in MFC (TCP)

Posted on 1998-12-28
1
Medium Priority
?
1,024 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 450 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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
Integration Management Part 2
Suggested Courses

810 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