Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UDP multi client server basics

Tags:

c

linux

udp

I'm looking forward to achive this: Server recieves from number of clients a string(file name) which he has to take from the folder and return it to the the client by a bufferSize which is defined from the command line. It has to be implemented with UDP communication. i'm familiarized with TCP sockets, but i don't get how can i get a fileDescriptor for the udp connection since accepts is missing.

So I'm thinking about this: after the config i do a while-loop in the server where i get 'some kind of descriptor' which i'll send to a new thread which knows where to send the data back... Any ideas?

I've checked the net but didn't found a concrete explanation for this kind of operation.

like image 620
Bogdan M. Avatar asked Feb 17 '23 23:02

Bogdan M.


1 Answers

You don't get connections with UDP; you use sendto() and recvfrom() to send and receive messages.

So the server will call recvfrom() on the socket; unwrap the request from the data it receives, do the appropriate actions, and use sendto() to send the response back to the client from which the request was received.

The client will call sendto() to package a message to the server, and then call recvfrom() to get the response. Note that UDP is an unreliable protocol; there is no guarantee that each message will be delivered. The client has to implement timeouts in case the server dropped a UDP request. Servers have to be able to deal with duplicate requests, too.

like image 142
Jonathan Leffler Avatar answered Feb 27 '23 00:02

Jonathan Leffler