lec7_client (1)

lec7_client (1) - Network Programming: Clients and HTTP...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Network Programming: Clients and HTTP Marco Gruteser Network-Centric Programming
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Typical Socket Implementation of  Client-Server Scenario Socket() Connect() Write() Read() Close() TCP Client Socket() Accept() Read() Close() Write() Bind() Listen() TCP Server Connection Establishment Request Reply
Background image of page 2
3 Connecting to a server Int connect(sockfd, servaddr, addrlen) Requires open socket and destination address Several possible errors: ETIMEDOUT – no response received after connection attempt ECONNREFUSED – the server has refused the connection attempt (often wrong IP or port number) EHOSTUNREACH – a router has notified the client that the destination could not be found
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 IPv4 Socket Address Structures struct in_addr { unsigned int s_addr; }; struct sockaddr_in { short int sin_family; /* Address family */ unsigned short int sin_port; /* Port number */ struct in_addr sin_addr; /* Internet address */ /* Pad to size of `struct sockaddr'. */ unsigned char __pad[__SOCK_SIZE__ - sizeof(short int) - sizeof(unsigned short int) - sizeof(struct in_addr)]; };
Background image of page 4
5 Address Conversion Convert string representation (“192.168.0.2”) into binary representation “Presentation” to/from “Numeric” Int inet_ p to n (family, strptr, addrptr) Char* inet_ n to p (family, addrptr, strptr, len)
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 Client Example Int main(int argc, char **argv) { int sockfd, n; char recvline[MAXLINE + 1]; struct sockaddr_in servaddr; if (argc != 2) err_quit("usage: a.out <IPaddress>"); if ( (sockfd = socket( AF_INET, SOCK_STREAM, 0)) < 0) err_sys("socket error");
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/21/2012 for the course ECE 456 taught by Professor Marcogruetesor during the Spring '12 term at Rutgers.

Page1 / 20

lec7_client (1) - Network Programming: Clients and HTTP...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online