Re: CSocket 10038 WSAENOTSOCK Error
Thanks for your reply. I am not sure if I have get it wrong. Cause what I
have done is as follows:
Server
-------
AfxSocketInit();
CSocket* serverSocket = new CSocket();
if(serverSocket->Create(111))
{
printf("Server socket created\n");
if(serverSocket->Listen())
{
printf("Server socket start to listen\n");
}
}
Client
-------
CSocket* sock = new CSocket();
if(sock->Connect"127.0.0.1", 111))
{
printf("Client socket connected");
string msg = "test";
if(sock->Send(msg.c_str(), strlen(msg.c_str())))
printf("Sent");
}
Is it wrong to do that? Really appreciate your help.
"Scott McPhillips [MVP]" wrote:
cleohm wrote:
Hi,
I am currently implementing a server socket that listen to a particular port
on the local machine as well as another client socket that connect to the
same port on the same machine. Everything goes fine until I attempt to send
data using the client socket. When I call GetLastError(), I got the error
code 10038 - WSAENOTSOCK.
I suspect that the error is due to me trying to listen and connect on the
same port and address. I tried to use SetSockOpt as follow:
serverSocket->SetSockOpt(SO_REUSEADDR, &nOption, 1);
It is still not successful. Does anyone have any idea how I can resolve
this problem?
There are two port numbers associated with a client socket. One of them
is the client's own and the other is the server to call. When calling a
server on the same machine these two port numbers must be different
because the IP:port pair is used to uniquely identify each socket.
Typical practice is to let the system select the client's own port (pass
NULL to CSocket::Create, and pass the server port to CSocket::Connect).
CSocket is part of the MFC library, so if you have follow up questions
try the MFC newsgroup for best results.
--
Scott McPhillips [VC++ MVP]