Socket Programming

QurazyQuisp

Platinum Member
Feb 5, 2003
2,554
0
76
Does anyone have any decent troubleshooting tips for socket programming? I'm trying to receive some UDP packets (connectionless) and it's sitting at the recvfrom line (So not actually receiving anything)

I'm writing in C++.

I'm just really looking for some general ways to figure out what's going wrong. I've never had to deal with socket programming before, and so the potential to lose data isn't something that I'm used to.
 

dighn

Lifer
Aug 12, 2001
22,820
4
81
make sure the socket is bound to the correct address and port.
Wireshark is a VERY useful tool when dealing with socket programming as it allows you to confirm what you are sending/receiving.
 

QurazyQuisp

Platinum Member
Feb 5, 2003
2,554
0
76
Originally posted by: dighn
make sure the socket is bound to the correct address and port.
Wireshark is a VERY useful tool when dealing with socket programming as it allows you to confirm what you are sending/receiving.

Unless there is a problem with the server program my professor gave us, I'm pretty sure I have the correct IP/Port. I grabbed the ip of the computer I'm connected to/working on via a ping, and I have the client program output the port when it first starts up. (Having the kernel pick a port)

Unfortunately, I'm not sure if I'll be able to use wireshark as our programs have to compile on these servers in order for us to get credit. I can't install anything on the servers. :(
 

dighn

Lifer
Aug 12, 2001
22,820
4
81
Originally posted by: QurazyQuisp
Originally posted by: dighn
make sure the socket is bound to the correct address and port.
Wireshark is a VERY useful tool when dealing with socket programming as it allows you to confirm what you are sending/receiving.

Unless there is a problem with the server program my professor gave us, I'm pretty sure I have the correct IP/Port. I grabbed the ip of the computer I'm connected to/working on via a ping, and I have the client program output the port when it first starts up. (Having the kernel pick a port)

Unfortunately, I'm not sure if I'll be able to use wireshark as our programs have to compile on these servers in order for us to get credit. I can't install anything on the servers. :(

so your client program selects a port, displays it, and then you enter this port into the server program provided by the prof? In that case I guess there's not much room for error there. I was also gonna suggest firewall being an issue but it being a controlled environment probably not.
 

QurazyQuisp

Platinum Member
Feb 5, 2003
2,554
0
76
Yeah, I really have no idea what could be going on here... the server program will send a message every 5 seconds to the IP/Port that we provide via command line. My program just sits at the recvfrom line waiting, I'm assuming.
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
Run Wireshark on your local computer after you input the port to the server to make sure the server is actually doing what you think it is.
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,835
4,815
75
Personally, I like NetCat. It lets you send or receive text to or from any port over TCP or UDP. That way you can simulate your server with a NetCat, and/or listen to make sure the real server is working.

For instance, "nc -l -p 4747 -u" will listen on UDP port 4747. "nc -u localhost 4747" will connect to it on the same machine. Use Ctrl-C to end a NetCat session.
 

degibson

Golden Member
Mar 21, 2008
1,389
0
0
Originally posted by: QurazyQuisp
Yeah, I really have no idea what could be going on here... the server program will send a message every 5 seconds to the IP/Port that we provide via command line. My program just sits at the recvfrom line waiting, I'm assuming.

It sounds a lot like this 'server' program is a client and your program is the server... who is listening for whom?

Check your return values from bind(). If negative, check errno. Verify that your flags to recvfrom() are zero, your length passed to recvfrom() is correct.