Search code examples
mfcclient

CSocket::Create() returns 0


I've connecting other process with socket connecting. So I create client socket which is object of CSocket Class. And I call Create method in CSocket class and I make my own program. But It doesn't work in create. It returns 0 value. Please tell me why does this happens.

Here's my brief code

CSocket *socket = new CSocket();
if(socket->Create())
   if(socket->Connect("127.0.0.1",0))
     socket->Send(widthCap, sizeof(widthCap));
socket->Close();

Solution

  • Call GetLastError() and look the value up here. I would guess that you have a firewall that blocks your exe. Remember that adding your exe to your firewall exception list will not help as you probably build a new exe every time you hit F5.