[ee122] sendto and recvfrom

Davide Cerri davide.cerri at gmail.com
Fri Nov 23 18:06:04 PST 2007

I don't understand how to establish a permanent connection. As a
client we create a socket and we return a fd. After that step the
client set the ip address and port of the server to establish a
connection. from that structure that is passed in connect we can
extract the information about the server. so we can use sentto to
communicate with the server. The server receives the message with
recvfrom (since there is no accept in udp). Here's my 2 questions:
1 - if the server side receives with recvfrom, do we need to know the
address of the sender a priori? and if it so how can the server side
obtain that information?
2 - If the client cannot specify the port that is sending from, how
can we communicate which port are using to the server? are we assured
that once we create a socket the socket will be always connected to
the same port? can we bind (UDP) sockets?

the man pages usually specify which type of sockets can use specific
functions (ex. listen), but for bind there is no specification, and i
am assuming that every socket need to be able to be bind() to a
specific port if we want to be able to advertise that port for
incoming messages. Still after we call bind() on a socket, if we use
recvfrom() then we need to know who is ending the message.
3 - How can we use a UDP socket to receive messages from any user?


~/Davide Cerri
$sudo yes | rm -Rf /

More information about the ee122 mailing list