• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Anand Baumunk

UDP-Based Client | Packets don't reach server

10 posts in this topic

Hello there, 

 

I've got a problem with my UDP-based gameserver I'm working on.

Everything is running fine when server and clients are running on the same machine and connecting to localhost.

When I have everything running on the same machine but use my public IPv4, packets send by the client are reaching the server, but not the other way around.

When clients and server are running on different machines, none of them are able to recv packets from each other.

 

 

I'm using  c++ and winsocks. The port I'm using is open, the IP-address is correct. Server is accepting INADDR_ANY. For testpurposes I'm using the most basic server/client possible in c++, just the

WSAStartup(MAKEWORD(2 ,0), &wsa); SOCKET s = socket(AF_INET,SOCK_DGRAM, IPPROTO_UDP); 
sendto(s, sendBuf, sizeof(sendBuf), 0, (SOCKADDR*)&addr, sizeof(SOCKADDR_IN));

and a bind for the server. Nothing is returning errors and the server is allowed as acception by the firewall.

 

I can't seem to find stuff regarding my problem, so I choose to ask this question here. Is every little UPD-program required to do some kind of punchtrough, or am I missing something? 

I'd really apprechiate any kind of help, I grew really desperate with this.

 

Thanks so much for your concern!

Edited by gnomgrol
0

Share this post


Link to post
Share on other sites

If your machines are on the same network your router has to allow NAT loopback/ for you to be able to use the public IP (not all routers support it and when it is supported it is normally disabled by default), if its not supported you will have to use the LAN ip when the client is on the same network as the server.

 

The server should always respond on the same socket it recieves from (otherwise firewalls will block the traffic) (a fairly common mistake is to open 2 sockets on the client (one to send and one to recieve, and that just won't work), the server gets the correct port and ip to send to from the recvfrom call.

Edited by SimonForsman
1

Share this post


Link to post
Share on other sites

Another possibility is that you are not resolving the IP correctly. Have you tried using connect instead and send? This way you may check if the server name resolution is correct.

 

Here is an example (this example uses localhost - 127.0.0.1 - and port 27015, you must, of course, change it for your server IP and port):

http://msdn.microsoft.com/en-us/library/windows/desktop/ms737625%28v=vs.85%29.aspx

 

For testing purposes you can also use nc (netcat), just config it to use udp instead of the default tcp.

0

Share this post


Link to post
Share on other sites

Right -- where does the value of addr come from? Are you properly using htons() for the port in there? Are you setting the sin_af field? Where do you get the address value from?

Also, you might as well pass in 2,2 for the WinSock version number -- it's been the current version for 15 years or so.

0

Share this post


Link to post
Share on other sites

The server should always respond on the same socket it recieves from (otherwise firewalls will block the traffic) (a fairly common mistake is to open 2 sockets on the client (one to send and one to recieve, and that just won't work), the server gets the correct port and ip to send to from the recvfrom call.

That was actually why it was working only one way when using my public IP, thanks!

Unfortunately, it still does not work with client and server not in the same network, I'm still not getting any packets.

Another possibility is that you are not resolving the IP correctly.

Are you properly using htons() for the port in there?

 

Both of those are fine.

 

 Are you setting the sin_af field? Where do you get the address value from?

What sin_af field are you talking about? The address is from the recvfrom (for the server) and set like this in the client: 

memset(&addr, 0, sizeof(SOCKADDR_IN)); 
addr.sin_family = AF_INET;
addr.sin_port = htons(1337);
addr.sin_addr.s_addr = inet_addr("192.52.25.175");
Edited by gnomgrol
0

Share this post


Link to post
Share on other sites

Are you checking the return of the inet_addr? It may be returning error.

 

I checked your code against mine, the only difference I found is that in my client I use inet_aton instead to start the address (and I use connect/receive/send instead of receive_from/sendto).

1

Share this post


Link to post
Share on other sites

Okey, I fixed it! Your last tip was pointing me in the right direction, one needs to call bind and connect in the client, and then use send. Thanks a bunch!

EDIT: Well, not quite. Bind does not seem to have much effect in the client, calling connect is the thing allowing packets to be send and recived. But, when I use it like this in different networks, it drops like 70% of all packets (I know UDP is supposed to work like this, but THAT many?), and after a few seconds, it simply dies. Since this only happens  when using this on different PCs, i can't quite debug the client that way :/

Do you have any idea what could cause this?

Edited by gnomgrol
0

Share this post


Link to post
Share on other sites

Check your send and receive buffer sizes - if you don't explicitly set them they can be quite small (something like 4K bytes I think). Any packets that overflow these buffers when sending or receiving are just dropped. I think the funtion is called setsockopt().

0

Share this post


Link to post
Share on other sites

Are you timing the sends (for instance, 1 per second) or sending packets in an infinite loop? If you are not timing you will surelly send way more packages than your network can handle and you will drop a load of them. Program dieing is likely some problem with your buffers.

Edited by KnolanCross
0

Share this post


Link to post
Share on other sites

connect() shouldn't matter at all for UDP as long as you use sendto(). It just allows you to use send() instead of sendto(). Note that on the server, you cannot call connect() at all, because you will need to send datagrams to all different clients on the same socket.

 

What does WireShark say on the sending and receiving machines when it works, and when it doesn't work?

0

Share this post


Link to post
Share on other sites

Kinda strange. Using connect and send in the client, while using recv instead of recvfrom in the server fixed it. I can't really see why, but still, thanks for your help!

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0