Search code examples
network-programmingtcpudp

differences of n in TCP and UDP?


This is kind od exam question, n is equal to?

write(sfd,buf,1024) (server)

n = read(cfd,buf,2048) (klient)

buf is not important, max size of buff (1024 and 2048)


Solution

  • Both read and write return the number of bytes read/written, or -1 on error.

    Note, that to be able to invoke read/write on a UDP socket (or, more generally, on a datagram socket) you have to invoke connect on it beforehand to specify the peer address.