0
1
I have two C programs running on separate computers, and I'm having some trouble sending UDP packets from one machine to the other. I've tested the client/server communication pieces of code on the same machine using a localhost, and everything seemed fine, so I don't think the problem is in my code. The server program is running on an Ubuntu laptop, and the client program is running on a Windows XP desktop. Right now, I simply have them both connected through a linksys wrt54gs router.
Every time I try to connect, I get the error "Cannot resolve address "10.0.24.100" " from the client PC when trying to establish a connection. (I can provide some code if anyone thinks that will help.) It's also giving me windows socket error code 11004.
"The requested name is valid and was found in the database, but it does not have the correct associated data being resolved for. The usual example for this is a host name-to-address translation attempt (using gethostbyname or WSAAsyncGetHostByName) which uses the DNS (Domain Name Server). An MX record is returned but no A record—indicating the host itself exists, but is not directly reachable."
I have no idea how to remedy this. However, the host PC is giving me a success message for sending data. (Is this because it's UDP?)
I think the problem is related to my lack of networking experience. This is my first time trying to send UDP data in C, and I'm relatively sure the client can't see the server because I haven't done something right in the settings somewhere. I'm new to linux networking, so I'm not sure how to ensure that the client can see my server in linux.
So far, I've tried two different routers to no avail. The LEDs come on when I plug the Ethernet cables in. I'm really not sure what else I need to do with the router to facilitate this communication. How can I make sure that the two machines can see each other? Do I have to change the IP of the router/computers? How would I go about doing this? I think there's something basic that I'm missing here. Any help would be much appreciated.
UPDATE
Here's the UDP Client Code:
int argc;
char **argv;
#define DEFAULT_PORT 61003
#define DEFAULT_PROTO SOCK_DGRAM
...
int UDPTrack(int argc, char **argv)
{
short pan1, tilt1;
char c = 'l';
char Buffer[128];
//server hardcoded in
char *server_name= "10.0.24.100";
unsigned short port = DEFAULT_PORT;
int retval, loopflag = 0;
int i, loopcount, maxloop=-1;
unsigned int addr;
int socket_type = DEFAULT_PROTO;
struct sockaddr_in server;
struct hostent *hp;
WSADATA wsaData;
SOCKET conn_socket;
//radar data struct
struct RadarData
{
unsigned int messageID : 32;
unsigned int time : 32;
float az;
float el;
};
struct RadarData receivedData;
if (argc >1)
{
for(i=1; i<argc; i++)
{
if ((argv[i][0] == '-') || (argv[i][0] == '/'))
{
switch(tolower(argv[i][1]))
{
case 'p':
if (!stricmp(argv[i+1], "TCP"))
socket_type = SOCK_STREAM;
else if (!stricmp(argv[i+1], "UDP"))
socket_type = SOCK_DGRAM;
else
Usage(argv[0]);
i++;
break;
case 'n':
server_name = argv[++i];
break;
case 'e':
port = atoi(argv[++i]);
break;
case 'l':
loopflag =1;
if (argv[i+1]) {
if (argv[i+1][0] != '-')
maxloop = atoi(argv[i+1]);
}
else
maxloop = -1;
i++;
break;
default:
Usage(argv[0]);
break;
}
}
else
Usage(argv[0]);
}
}
if ((retval = WSAStartup(0x202, &wsaData)) != 0)
{
fprintf(stderr,"Client: WSAStartup() failed with error %d\n", retval);
WSACleanup();
return -1;
}
else
printf("Client: WSAStartup() is OK.\n");
//ERROR HAPPENS SOMEWHERE IN HERE
if (port == 0)
{
Usage(argv[0]);
}
// Attempt to detect if we should call gethostbyname() or gethostbyaddr()
if (isalpha(server_name[0]))
{ // server address is a name
hp = gethostbyname(server_name);
}
else
{ // Convert nnn.nnn address to a usable one
addr = inet_addr(server_name);
hp = gethostbyaddr((char *)&addr, 4, AF_INET);
}
if (hp == NULL )
{
fprintf(stderr,"Client: Cannot resolve address \"%s\": Error %d\n", server_name, WSAGetLastError());
WSACleanup();
system("Pause");
exit(1);
}
else
printf("Client: gethostbyaddr() is OK.\n");
I can never get past here.
UDP streams dont use states or connection, its just streams of data, you will not have a connection between client and server. How are you tring to connect client to server??? You can only do this by implementing client/server on your code. You can test the link betwwen both machines with ping. – Diogo – 2011-07-14T16:06:59.757
Sorry, I should have clarified. I was referring to the computer receiving data as the 'client' and the computer sending data as the 'server'. – Mike – 2011-07-14T16:53:05.827
1So to test connectivity between both you can just use with ping. If ping works then you can test your aplication. It would be a good strategy of test. – Diogo – 2011-07-14T16:59:55.497
You can greatly simplify your testbed network by installing a NIC or USB Ethernet adapter in the client and server PCs, and then assigning static IP addresses. Connect the NICs to each other using a crossover cable or each Ethernet port to a switch. You now have the simplest LAN possible. – sawdust – 2011-07-14T19:25:19.900
I am now able to ping the laptop sending data from the desktop (supposed to be) receiving data. I am still getting the same error when trying to use my program. – Mike – 2011-07-14T21:00:35.857
UDP client code is now above. It's worth noting that this worked as a 'client' when receiving data from a localhost UDP broadcast. – Mike – 2011-07-14T21:14:43.333