Thanks for your reply Salem. The thing is, I dont get an either a compile error nor a run-time error.
What my server program does is basiclly output to the screen whatever is send to it.
If I compile the server program with the ip 10.0.0.10 (which is my computer ip address) and I then send a msg to that address from another program the server program prints the message onto the screen. This is very nice but not very flexible since the server program is limited to computers using the ip 10.0.0.10.
So like I sayed about, I tryed to set the address to 127.0.0.1 and then run the program, if I then send a message to the server (I still send the message to ip 10.0.0.10 which is the server ip) nothing happens (i.e. it does not print out any message).
The only difference between the two is the ip address.
So my question is bascilly, how can I figure out the ip address on the computer that my server program is running ?
Hope this makes sense, if not please let me know.
Here is the server code,
Code:
int MAX_DGRAM_SIZE = 1024;
char inBuf[MAX_DGRAM_SIZE];
initWinsock(); /* init's the winsock */
if ((id = socket(AF_INET,
SOCK_DGRAM,
IPPROTO_UDP)) == INVALID_SOCKET)
{
return SOCK_ERROR;
}
if(bind(id, reinterpret_cast<sockaddr*>(&host), sizeof(host)) == SOCKET_ERROR)
{
cout << "WSAGetLastError = " << WSAGetLastError() << endl;
return SOCK_ERROR;
}
int len = sizeof(struct sockaddr);
while(1)
{
if(recvfrom(id, inBuf, MAX_DGRAM_SIZE, 0, reinterpret_cast<sockaddr*>(&target), &len) == SOCKET_ERROR)
{
cout << "WSAGetLastError = " << WSAGetLastError() << endl;
return SOCK_ERROR;
}
cout << "Result=" << inBuf << endl;
}
WSACleanup();
return 0;