20.01.2014 Views

Lectures notes for 2010 - KTH

Lectures notes for 2010 - KTH

Lectures notes for 2010 - KTH

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Socket API<br />

• int socket(int domain, int type, int protocol);<br />

• creates an endpoint description that you can use to send and receive network traffic<br />

• int bind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen);<br />

• binds a socket to the local address and port: my_address<br />

• int connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen);<br />

• connect the local socket to a remote socket<br />

• int listen(int s, int backlog);<br />

• indicates that socket is willing to accept connections & limites the queue of pending<br />

connections<br />

• int accept(int s, struct sockaddr *addr, socklen_t *addrlen);<br />

• accepted the first connection request from the queue and connects it to the socket<br />

• connection oriented sending and receiving:<br />

• ssize_t send(int s, const void *buf, size_t len, int flags);<br />

• ssize_t recv(int s, void *buf, size_t len, int flags);<br />

• datagram sending and receiving:<br />

• ssize_t sendto(int s, const void *buf, size_t len, int flags, const struct sockaddr *to, socklen_t tolen);<br />

• ssize_t recvfrom(int s, void *buf, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen);<br />

• int close(int fd) and int shutdown(int s, int how) - end it all!<br />

Maguire Socket API 4: 18 of 74<br />

maguire@kth.se <strong>2010</strong>.03.21 Internetworking/Internetteknik

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!