UDP Client's

Started by
15 comments, last by Wickeeed 19 years, 10 months ago
Hi to all, i was trying to run a UDP Server, and i found out what there is no accept function inside ! and i wonder how do i have to listen clients if i dont even know thair sockets? mfg wicked
Advertisement
A recvfrom() call will give the source address of the received packet.
With UDP you usually don't have a single port per client, but rather one port for everyone. Like the op stated, you can get the address of the sender with recvfrom(), and you can send messages directed at a specific address from the same socket.


Looking for a serious game project?
www.xgameproject.com

[edited by - Max_Payne on April 21, 2004 7:55:54 PM]

Looking for a serious game project?
www.xgameproject.com
With UDP, you open up one port and let other people send data to you via that port. Clients connecting must know your ip and port to connect to. The same way you would connect to a Quake 2 server. Depending on whether or not you have blocking enabled, you would simply poll that port for incoming. If data is waiting to be read from that port, you will get it and the address of the client who sent it. Everything from that point is application/protocol specific.

Intro Engine
my problem is that if i have 15 fast clients and 15 slow, then it may only recev messages from faster clients even if i recv messages 100 times every frame. i just dont know how to recv messages from all clients without waiting :|

edit: can this be that recvfrom() is blocking like accept `? ???

[edited by - Wickeeed on April 22, 2004 6:03:25 AM]
By default (in winsock) sockets are created as blocking.

For non-blocking action either use ioctlsocket() to set the socket to non-blocking mode or better still use the WSAAsyncSelect/WSAEventSelect functions to activate asynchronous message/event notifications.


[edited by - arm on April 22, 2004 6:31:24 AM]
quote:Original post by arm
By default (in winsock) sockets are created as blocking.

For non-blocking action either use ioctlsocket() to set the socket to non-blocking mode or better still use the WSAAsyncSelect/WSAEventSelect functions to activate asynchronous message/event notifications.



how to use WSAAsyncSelect/WSAEventSelect ??? is that the same thing like select in TCP ?? can i use them if i only know client's ip's and nothin else.

is ioctlsocket() the best thing for UDP recvfrom()?
edit: or shul i make a thread for this?




[edited by - Wickeeed on April 22, 2004 6:44:31 AM]
WSAAsyncSelect() tells winsock to message a window whenever a network event occurs. You can select the events that cause notifications.

WSAEventSelect() tells winsock to set an Event object whenever a network event occurs. Again, you can select the events that cause notifications.

ioctlcsocket() simply makes calls like recvfrom non-blocking so that if you call them and there is no data available, they will just return an error - you have to keep polling them until data is available.

Look at the documentation to learn more about the above functions. I cant tell you which one will fit best into your application.
If i get it all right then that means that if i wuld use two TCP servers, one on blocking socket and one on non-blocking socket.. then the one that runs on non-b TCP will be like UDP and have the same speed ??? or it will be still slower ?

arm: i have searched a lot on google and still cant find a good tutorial or fag about these functions..
more questions::: how to chek a socket with udp for messages ?? loke select do in tcp ?????

This topic is closed to new replies.

Advertisement