Question about using CSocket writing a server
-
Hello, I wonder what is the usage of using Bind method after creating a CSocket in the server. I get an error message when I Bind the socket, however, if I ignore the error, I can still receive the message come from the client. So, what is the usage of using Bind method in server side? Actually, my code is something like this, rt = cs.Create(1000, SOCK_STREAM, "127.0.0.1"); if (rt == 0) Print_Error(); rt = cs.Bind(1000, "127.0.0.1"); if (rt == 0) Print_Error(); When the program is going to bind the socket, it return error message 10022, which the documentation told me that is "invalid argument" exception. Can someone told me what is my problem? Thanks! Nachi:(
-
Hello, I wonder what is the usage of using Bind method after creating a CSocket in the server. I get an error message when I Bind the socket, however, if I ignore the error, I can still receive the message come from the client. So, what is the usage of using Bind method in server side? Actually, my code is something like this, rt = cs.Create(1000, SOCK_STREAM, "127.0.0.1"); if (rt == 0) Print_Error(); rt = cs.Bind(1000, "127.0.0.1"); if (rt == 0) Print_Error(); When the program is going to bind the socket, it return error message 10022, which the documentation told me that is "invalid argument" exception. Can someone told me what is my problem? Thanks! Nachi:(
You are already binding the socket in the constructor, so the extra call to
Bind
is superfluous. I guess you are misinterpreting the error code (this should be retrieved withWSAGetLastError
and looked upon in the Winsock error table provided by the documentation. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo -
You are already binding the socket in the constructor, so the extra call to
Bind
is superfluous. I guess you are misinterpreting the error code (this should be retrieved withWSAGetLastError
and looked upon in the Winsock error table provided by the documentation. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo