Click to See Complete Forum and Search --> : Socket Programming MFC


sivaprakash.shanmugam
May 29th, 2006, 07:04 AM
I'm using following statements to create socket application. The g1->Create(5051) statement always return false, as well it doenst return any Exception whats wrong with this code.

MFC ActiveX VC++.Net
--------------------

CSocket *g1 = new CSocket ();
if (g1->Create(5051))
AfxMessageBox ("Hi");
g1->Listen();
CSocket *g=new CSocket;
g1->Accept(*g);

wildfrog
May 29th, 2006, 09:15 AM
The g1->Create(5051) statement always return false, as well it doenst return any Exception whats wrong with this code.MSDN on CSocket::Create:

Return Value

Nonzero if the function is successful; otherwise, it is zero, and a specific error code can be retrieved by calling GetLastError.

So, you should check what GetLastError() has to say to determine why Create(...) fails.

- petter