Solved

WinSock programming in MFC (TCP)

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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…
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.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now