Problems with UDP connections

Blitz3D Forums/Blitz3D Programming/Problems with UDP connections

Storm8191(Posted 2005) [#1]
Hi, for the past month or so I've been working on a networking library of mine. It's somewhat like BlitzPlay, in that it's designed to handle as many networking issues as possible. So far it's working fairly well, and all tests on a local machine work fine. However, I've run into problems with other people not being able to send or receive any messages at all.

I've written a program I call DistriChat, which is a p2p-style chat system. It uses GNet to find one PC, then once it's connected to that user, it shares the remaining IP addresses of all other connected users. If the 'host' user, the one with their IP listed on GNet, leaves, a new user will become the host.

So far I have had a few people able to connect and chat with me, using my program. However others are able to find the proper IP address from GNet, but cannot connect to any other users. This problem seems to happen to more people than I am able to connect with.

I can't say I know a whole lot about routers or firewalls so it might actually be a problem with the PCs I use (I don't own a PC of my own, I rely on the computer labs at my university). My programs mostly use 7000, but my library will increment its port number repeatedly, if a given port number is unavailable (as decided by Blitz's CreateUDPStream() ).

Should I simply start with a different port number or is there something seriously wrong here?


jfk EO-11110(Posted 2005) [#2]
I think using 7000 and higher as a port number may be difficult since, as you say, many firewalls are using autosettings that are blocking any "uncommon" port activities. I think the MS firewall is probably doing so, and I surely know a lot of hardware firewalls that are part of cheap routers, eg. Netgear, are doing this as well. The user has to log in for the Router settings at 192.168.0.1 or so, and explicitely allow an "uncommon" port, eg. 7000, or a range. Something that is beyond most users horizons.

A solution for this problem could be to use very common ports, but leave the user some alternatives, so if they want to use MSN for MSN and not for your App, they may use Telnet for your App instead. Of course, this isn't the most elegant way, but it seems to be one that works out of the box.

An other issue with UDP is, the protocol doesn't include error-correction as TCP does, so you have to make this by your own: send and check Checksums of each packet, and if the checksum doesn't fit, re-order a packet etc. In LANs you probably won't get any errors, but as soon your bits have to travel around the globe, you better check if they arrived in their original state.


ICECAP(Posted 2005) [#3]
Try using port 80. This is the port at which all your webpages pass through. Therefore most firewalls wont have that port blocked.

It might fix your problem.


Rottbott(Posted 2005) [#4]
However, you can't use 80 on the same machine as a web server.

I use port 25,000 for my network stuff and have no problems at all. Only hosts should need to alter firewall settings, people connecting should not.


Rook Zimbabwe(Posted 2005) [#5]
I was wondering about this myself... That an how can I see what is on my network neighborhood without opening windows... anyone have good ideas about that?
-RZ


jfk EO-11110(Posted 2005) [#6]
without opening windows? probably with linux. or "lan for dos" or something. well I guess I misunderstood your question.


Storm8191(Posted 2005) [#7]
Rott, I don't think you quite understand how UDP works. UDP works basically on a shout-and-send principle. All you can really do is send messages, and hope the receiver gets it. The only way to tell if they're really still connected to you is to listen for replies. TCP, on the other hand, is designed for reliable data sends. A TCP system uses ACK reply packages and error checking to guarantee that a message arrives at its destination intact. My library actually has a mock TCP data send, that performs these operations.

I actually had few a successful tests lately. I first tried hosting an was unable to get others to connect. But when someone else hosted I was able to chat with them, and everything worked fine after that. I'm just confused as to why I was able to initiate contact with him, and then get proper communications, while he was unable to initiate contact with me. If anyone has any ideas as to why this is the case, please let me know.


KuRiX(Posted 2005) [#8]
I am working with TCP and UDP now and perhaps the problem is that UDP needs to know both ip's of both computers, not just only one, so if one of them hasn't a public ip, UDP will never work.

TCP in the other hand creates a connection between your computer and the other with public ip, so only one public ip is needed.

am i Wrong? Can i have only one public ip with UDP?


Rottbott(Posted 2005) [#9]
Storm, I understand it just fine. I've even written my own UDP library for Blitz. It's in the Toolbox. My library also has a reliable send option.

As far as routers/firewalls go they work in exactly the same way (they are both based on IP). The firewall should 'remember' who you have sent UDP messages to recently and allow incoming messages from that host.

Like I said, I use port 25,000 in my UDP stuff with no connection problems.


Wayne(Posted 2005) [#10]
This technical reference may help you:
http://alumnus.caltech.edu/~dank/peer-nat.html

bye


Storm8191(Posted 2005) [#11]
Rottbott: okay I couldn't really say how much you knew about UDP, sorry. I'm just certain that there is no actual requirement for someone to serve as host or for official connections to be made. Everything is open data sends.

I think this is down to issues with firewalls or NAT, as Wayne's article explains. I've been able to get connections working if I connect to the other person first, but not the other way around. Once a message is received, everything works as planned. I can see a small client-host setup working around this simply by the two people selecting a different host, but I plan on having things a bit more... flexible.

What I'd be interested in now is a way to detect connection problems like this. If I can determine that one user is unable to receive new data connections, I can prevent them from becoming a host, thus preventing any connection problems. If anyone has any ideas on how to detect this, I'd be grateful.

Thanks everyone.