ICS 451: Data Networks





Edo Biagioni


esb@hawaii.edu



Department of Information and Computer Science



ICS 451: Today's plan



ICS 451 Course Management



ICS 451 Course Contents



What is Networking, and why is it interesting?



Network Applications



Internet Service



Clients and Servers



Clients and Servers



Connection-Oriented Service



Sockets API



Connectionless Service



Unix Sockets API -- principles



Unix Sockets API -- Managing Connections

int socket(int domain, int type,
           int protocol);
int bind(int sockfd,
         struct sockaddr *my_addr,
         socklen_t addrlen);
int listen(int s, int backlog);
int accept(int s,
           struct sockaddr *addr,
           socklen_t *addrlen);
int connect(int sockfd,
            struct sockaddr *serv_addr,
            socklen_t addrlen);
int shutdown(int s, int how);
int close(int fd);

int gethostname(char *name, int len); struct hostent *gethostbyname(const char *n); struct protoent *getprotobyname(const char *n);



Unix Sockets API -- Sending and Receiving data

int send(int s, const void *msg,
         int len, int flags);
int sendto(int s, const void *msg,
           int len, unsigned int flags,
           const struct sockaddr *to,
           socklen_t tolen);
int write(int fd, const void *buf, int count);

int recv(int s, void *buf, int len, int flags); int recvfrom(int s, void *buf, int len, unsigned int flags, struct sockaddr *from, socklen_t *fromlen); int read(int fd, void *buf, int count);



Windows Sockets API

int WSAStartup(int version,
               WSADATA *implementation);
int WSACleanup();



Socket types



Reading a STREAM Socket

char buffer [BUFFER_SIZE];
int num_bytes, new_bytes, socket;

num_bytes = 0; do { new_bytes = recv (socket, buffer + num_bytes, BUFFER_SIZE - num_bytes); num_bytes += new_bytes; } while ((num_bytes < BUFFER_SIZE) && expecting_more (buffer, num_bytes));



HTTP



HTTP Client



HTTP server



HTML



Project 1



Project 1, continued