Writing Socket Programs

Size: px
Start display at page:

Download "Writing Socket Programs"

Transcription

1 Writing Socket Programs Laboratorio di Sistemi Operativi Corso di Laurea in Informatica Università degli Studi dell'aquila A.A. 2011/2012 Romina Eramo 1

2 Writing Socket Programs Any program that uses sockets must include the header files /usr/include/sys/types.h and /usr/include/sys/socket.h. Additional header files must be included based on the socket domain that you wish to use. The most commonly used domains are: Domain AF_UNIX AF_INET Addi*onal header files /usr/include/sys/un.h /usr/include/ne*net/in.h /usr/include/arpa/inet.h /usr/include/netdb.h 2

3 Different Kinds of Sockets Description of the socket-oriented system calls around a small clientserver example that uses AF_UNIX sockets. The AF_UNIX examples is made up of two programs: 1) chef, the server, which creates a named socket called recipe and writes the recipe to any clients who request it. The recipe is a collection of NULL-terminated strings of variable length. 2) cook, the client, which connects to the named socket called recipe and reads the recipe from the server. It displays the recipe to standard output as it reads it and then terminates. 3

4 Different Kinds of Sockets The chef server process runs in the background. Any client cook processes that connect to the server cause the server to fork a duplicate server to handle the recipe transfer, allowing the original server to accept other incoming connections. Here s some sample output from the chef and cook example: $ chef & ---> run the server in the background. [1] 5684 $ cook ---> run a client to display the recipe. spam, spam, spam, spam, spam, and spam. $ kill %1 ---> kill the server. [1] Terminated chef $ _ 4

5 Chef and Cook Listing Chef Server #include <stdio.h> #include <signal.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/un.h> /* For AFUNIX sockets */ #define DEFAULT_PROTOCOL 0 /**************************************************/ main() { int serverfd, clientfd, serverlen, clientlen; struct sockaddr_un serverunixaddress; /* Server address */ struct sockaddr_un clientunixaddress; /* Client address */ struct sockaddr* serversockaddrptr; /* Ptr to server address */ struct sockaddr* clientsockaddrptr; /* Ptr to client address */ 5

6 /* Ignore death-of-child signals to prevent zombies */ signal(sigchld, SIG_IGN); serversockaddrptr = (struct sockaddr*) &serverunixaddress; serverlen = sizeof( serverunixaddress ); clientsockaddrptr = (struct sockaddr*) &clientunixaddress; clientlen = sizeof( clientunixaddress ); /* Create a UNIX socket, bidirectional, default protocol */ serverfd = socket( AF_UNIX, SOCK_STREAM, DEFAULT_PROTOCOL ); serverunixaddress.sun_family = AF_UNIX; /*Set domain type */ strcpy( serverunixaddress.sun_path, recipe ); /* Set name */ unlink( recipe ); /* Remove file if it already exists */ bind(serverfd, serversockaddrptr, serverlen); /* Create file */ listen( serverfd, 5 ); /* Maximum pending connection length */ 6

7 while(1) /* Loop forever */ { /* Accept a client connection */ clientfd = accept( serverfd, clientsockaddrptr, &clientlen); if ( fork() == 0 ) /* Create child to send receipe */ { writerecipe( clientfd ) /* Send the recipe */ close(clientfd); /* Close the socket */ exit( /* EXIT_SUCCESS */ 0 ); /* Terminate */ } else close(clientfd); /* Close the client descriptor */ } } 7

8 /*************************************************/ writerecipe( fd ) int fd; { static char* line1 = spam, spam, spam, spam, ; static char* line2 = spam, and spam. ; write(fd, line1, strlen(line1)+1); /* Write first line */ write(fd, line2, strlen(line2)+1); /* Write second line */ } 8

9 Chef and Cook Listing Cook Client #include <stdio.h> #include <signal.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/un.h> /* For AFUNIX sockets */ #define DEFAULT_PROTOCOL 0 /*************************************************/ main() { int clientfd, serverlen, result; struct sockaddr_un serverunixaddress; struct sockaddr* serversockaddrptr; serversockaddrptr = ( struct sockaddr*) &serverunixaddress; serverlen = sizeof( serverunixaddress ); 9

10 serverlen = sizeof( serverunixaddress ); /* Create a UNIX socket, bidirectional, default protocol */ clientfd = socket( AF_UNIX, SOCK_STREAM, DEFAULT_PROTOCOL); serverunixaddress.sun_family = AF_UNIX; /* Server domain */ strcpy( serverunixaddress.sun_path, recipe ); /* Server name */ do /* Loop until a connection is made with the server */ { result = connect( clientfd, serversockaddrptr, serverlen); if ( result == -1 ) sleep(1); /* Wait and then try again */ } while ( result == -1 ); readrecipe( clientfd ); /* Read the recipe */ close( clientfd ); /* Close the socket */ exit( /* EXIT_SUCCESS */ 0 ); /* Done */ } 10

11 /************************************************/ readrecipe( fd ) int fd; { char str[200]; while ( readline(fd, str) ) /* Read lines until end of input */ printf( %s\n, str); /* Echo line from socket */ } /************************************************/ readline(fd, str) int fd; char* str; /* Read a single NULL-terminated line */ { int n; do /* Read characters until NULL or end of input */ { n = read( fd, str, 1 ); /* Read one character */ } while ( n > 0 && *str++!= NULL ); return( n>0 ); /* Return false if end of input */ } 11

12 Analyzing the Source Code An overview of a server - creating a server socket - naming a server socket - specifying the maximum number of pending connections to a sever socket - accepting connections on a server socket - serving a client An overview of a client - creating a client socket - connecting a client socket to the server socket - communicating via sockets 12

13 The Server A server is the process that s responsible for creating a names socket and accepting connections to it. To accomplish this task, it must use the following system calls in the order in which they presented : Name socket bind listen accept Meaning creates an unnamed socket gives the socket a name specifies the maximum number of pending connections accepts a socket connection from a client 13

14 Creating a Socket: socket() A process may create a socket by using socket(), which works like this: System Call : int socket( int domain, int type, int protocol ) socket() creates an unnamed socket of the specified domain, type, and protocol. The legal values of these parameters were described earlier in this section. If socket() is successful, it returns a file descriptor associated with the newly created socket; otherwise, it returns a value of -1. The chef server creates its unnamed socket (line 30): serverfd=socket(af_unix, SOCK_STREAM,DEFAULT_PROTOCOL); 14

15 Naming a Socket : bind() Once the server has created an unnamed socket, it must be bind it to a name by using bind(), which works like this: System Call : int bind( int fd, const struct sockaddr* address, size_t addresslen ) bind() associates the unnamed socket represented by file descriptor fd with the socket address stored in address. addresslen must contain the length of the address structure. The type and value of the incoming address depend on the socket domain. 15

16 Naming a Socket : bind() If the socket is in the AF_UNIX domain, a pointer to a sock-addr_un structure must be cast to a sockaddr* and passed in as address. This structure has two fields that should be set as follows: FIELD sun_family sun_path ASSIGN THE VALUE AF_UNIX the full UNIX pathname of the socket( absolute or relative ) If the named AF_UNIX socket already exists, an error occurs, so it s a good idea to unlink() a name before attempting to bind to it. 16

17 Naming a Socket : bind() If the socket is in the AF_INET domain, a pointer to a socket-addr_in structure must be cast to a sockaddr and passed in as address. This structure has four fields that should be set as follows: FIELD sin_family sin_port sin_addr sin_zero ASSIGN THE VALUE AF_INET the port number of the Internet socket a structure of type in_addr that holds the Internet address leave empty If bind() succeeds, it returns a value of 0; otherwise, it returns a value of

18 Naming a Socket : bind() The chef server assigns the sockaddr_un fields and performs a bind() on lines 31 to 34: serverunixaddress.sun_family = AF_UNIX; /* Set domain type */ strcpy( serverunixaddress.sun_path, recipe ); /* Set name */ unlink( recipe ); /* Remove file if it already exists */ bind( serverfd, serversockaddrptr, serverlen ) /* Create file */ 18

19 Creating a Socket Queue: listen() When a sever process is servicing a client connection, it s always possible that another client will also attempt a connection. The listen() system call allows a process to specify the number of pending connections that may be queued, and it works like this: System Call: int listen( int fd, int queuelength ) listen() allows you to specify the maximum number of pending connections on a socket. If a client attempts a connection to a socket whose queue is full, it is denied. 19

20 Creating a Socket Queue: listen() The chef server listens to its named socket, where it specifies a maximum queue length of five: listen( serverfd, 5 ); /* Maximum pending connection length */ 20

21 Accepting a Client : accept() Once a socket has been created, named, and its queue size has been specified, the final step is to accept connection requests from clients. To do so, the server must use accept(), which works as follows: System Call : int accept( int fd, struct sockaddr* address, int * addresslen ) accept() listens to the named server socket referenced by fd and waits until a connection request from a client is received. When this event occurs, accept() creates an unnamed socket with the same attributes as those of the original named server socket, connects it to the client s socket. and returns a new file descriptor that may be used for communication with the client. 21

22 Accepting a Client : accept() The original named server socket may be used to accept more connections. The address structure is filled with the address of the client and is normally only used in conjuction with Internet connections. The addresslen field should be initially set to point to an integer containing the size of the structure pointed to by address. When a connection is made, the integer that it points to is set to the actual size, in bytes, of the resulting address. If accept() succeeds, it returns a new file descriptor that may be used to talk with the client; otherwise, it returns a value of

23 Accepting a Client : accept() The chef sever accepts a connection clientfd = accept( serverfd, clientsockaddrptr, &clientlen ); Serving a client when a client connection succeeds, the most common sequence of events is as follows: The server process forks. The parent process closes the newly formed client file descriptor and loops back to accept(), ready to service new connection requests from clients. The child process talks to the client using read() and write(). When the conversation is complete, the child process closes the client file descriptor and exits. 23

24 Accepting a Client : accept() The chef sever process while( 1 ) /* Loop forever */ { /* Accept a client connection */ clientfd = accept( serverfd, clientsockaddrptr, &clientlen ); } if ( fork()==0 ) /* Create child to send receipe */ { writerecipe( clientfd ); /* Send the recipe */ close(clientfd); /* Close the socket */ exit( /* EXIT_SUCCESS */ 0 ); /* Terminate */ } else close(clientfd); /* Close the client descriptor */ 24

25 The Client A client is a process that s responsible for creating an unnamed socket and then attaching it to a named server socket. To accomplish this task, it muse use the following system calls in order in which they are presented: Name socket connect Meaning creates an unnamed socket attaches an unnamed client socket to a named server socket 25

26 Creating a Socket: socket() a client uses socket() to create an unnamed socket is the same as the way that the server uses it. The domain, type, and protocol of the client socket must match those of the targeted server socket. The cook client process creates its unnamed socket clientfd = socket( AF_UNIX, SOCK_STREAM, DEFAULT_PROTOCOL); 26

27 Making the Connection : connect() To connect to a sever s socket, a client process must fill a structure with the address of the server s socket and then use connect, which works like this: System Call: int connect(int fd, struct sockaddr* address,int addresslen) connect() attempts to connect to a sever socket whose address is contained within a structure pointed to by address. If connect() successful, fd may be used to communicate with the server s socket. The type of structure to which address points must follow the same rules as those stated in the description of bind() : 27

28 Making the Connection : connect() If the socket is in the AF_UNIX domain, a pointer to a sock-addr_un structure must be cast to a( sockaddr* ) and passed in as address. If the socket is in the AF_INET domain, a pointer t a sock-addr_un structure must be cast to a ( sockaddr* ) and passed in as address. addresslen must be equal to the size of the address structure. For examples of Internet clients, see the next examples of a socket and the Internet-shell program at the end of this chapter. If the connection is made, connect() returns a value of 0. If the server socket doesn t exist or its pending queue is currently filled, connect() returns a value of

29 Making the Connection : connect() The cook client process calls connect() until a successful connection is made. do /* Loop until a connection is made with the server */ { result = connect( clientfd, serversockaddrptr, serverlen ); if ( result == -1 ) sleep(1); /* Wait and then try again */ } while ( result == -1 ); 29

30 Communicating Via Sockets Once the server socket and client socket have connected, their file descriptors may be used by write() and read(). writerecipe(fd) int fd; { static char* line1= spam, spam, spam, spam, ; static char* line2= spam, and spam. ; write(fd, line1, strlen(line1)+1); /* Write first line */ write(fd, line2, strlen(line2)+1); /* Write second line */ } 30

31 Communicating Via Sockets The client uses read() readline( fd, str ) int fd; char* str; /* Read a single NULL-terminated line */ { int n; do /* Read characters until NULL or end of input */ { n=read(fd, str, 1); /* Read one character */ } while ( n>0 && *str++!= NULL ); } return ( n > 0 ); /* Return false if end of input */ The server and client should be careful to close their socket file descriptors when they are no longer needed. 31

32 Internet Sockets The AF_UNIX sockets that you ve seen so far are fine for learning about sockets, but they aren t where the action is. An Internet socket is specified by two values: a 32-bit IP address, which specifies a single unique Internet host, and a 16-bit port number, which specifies a particular port on the host. These specifications mean that an Internet client must know not only the IP address of the server, but also the server s port number. Several standard port numbers are reserved for system use. For example, port 13 is always served by a process that echoes the host s time of day to any client that s interested. 32

33 Internet Sockets The first example, allows the connection to port 13 of any Internet host in the world and find the remote time of day. It allows three kinds of Internet addresses: If you enter s, it automatically means the local host. If you enter something that starts with a digit, it s assumed to be an A.B.C.D-format IP address and is converted into a 32-bit IP address by software. If you enter a string, it s assumed to be a symbolic host name and is converted into a 32-bit IP address by software. 33

34 Internet Sockets Sample Output $ inettime ---> run the program. Host name ( q=quit, s=self ) : s ---> what s my time? Self host name is csservr2 Internet Address = The time on the target port is Fri Mar 27 17:03: Host name ( q=quit, s=self ): wotan ---> what s the time on wotan? Internet Address= The time on the target port is Fri Mar 27 17:03: Host name ( q=quit, s=self ): > what s the time at ---> ddn.nic.mil. The time on the target port is Fri Mar 27 18:02: Host name ( q=quit, s=self ): q ---> quit program. $ _ 34

35 Internet Time Client Listing #include <stdio.h> #include <signal.h> #include <ctype.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> /* For AFINET sockets */ #include <arpa/inet.h> #include <netdb.h> #define DAYTIME_PORT 13 /* Standard port 0 */ #define DEFAULT_PROTOCOL 0 unsigned long promptforinetaddress(); unsigned long nametoaddr(); /**************************************************/ main() { int clientfd; /* Client socket file descriptor */ 35

36 Internet Time Client Listing (2) int serverlen; /* Length of server address structure */ int result; /* From connect() call */ struct sockaddr_in severinetaddress; /* Server address */ struct sockaddr* serversockaddrptr; /* Pointer to address */ unsigned long inetaddress; /* 32-bit IP address */ /* Set the two server variables */ serversockaddrptr = ( struct sockaddr* ) &serverinetaddress; serverlen = sizeof ( serverinetaddress ); /* Length of address */ while( 1 ) /* Loop until break */ { inetaddress = promptforinetaddress(); /* Get 32-bit IP */ if ( inetaddress == 0 ) break; /* Done */ /* Start by zeroing out the entire address structure */ bzero( (char*)&serverinetaddress, sizeof( serverinetaddress)); 36

37 Internet Time Client Listing (3) serverinetaddress.sin_family = AF_INET; /* Use Internet */ serverinetaddress.sin_addr.s_addr=inetaddress; /* IP */ serverinetaddress.sin_port = htons(daytime_port); /* Now create the client socket */ clientfd = socket( AF_INET, SOCK_STREAM, DEFAULT_PROTOCOL); do /* Loop until a connection is made with the server */ { result = connect( clientfd, seversockaddrptr, serverlen ); if ( result== -1 ) sleep(1); /* Try again in 1 second */ } while ( result==-1 ); readtime( clientfd ); /* Read the time from the server */ close(clientfd); /* Close the socket */ } exit( /* EXIT_SUCCESS */ 0 ); } 37

38 Internet Time Client Listing (4) /************************************************/ unsigned long promptforinetaddress() { char hostname[100]; /* Name from user: numeric or symbolic */ unsigned long inetaddress; /* 32-bit IP format */ /* Loop until quit or a legal name is entered */ /* If quit, return 0; else return host s IP address */ do { printf( Host name( q=quit, s=self) : ); scanf( %s, hostname); /* Get name from keyboard */ if ( strcmp(hostname, q ) == 0 ) return (0); /* Quit */ inetaddress = nametoaddr(hostname); /* Convert to IP */ if ( inetaddress == 0 ) printf( Host name not found \n ); } while( inetaddress==0 ); } 38

39 Internet Time Client Listing (5) /************************************************/ unsigned long nametoaddr(name) char* name; { char hostname[100]; struct hostent* hoststruct; struct in_addr* hostnode; /* Convert name into a 32-bit IP address */ /* If name begins with a digit, assume it s a valid numeric */ /* Internet address of the form A.B.C.D and convert directly */ if ( isdigit(name[0]) ) return ( inet_addr(name) ); if ( strcmp(name, s ) ==0 ) /* Get host name from database */ { gethostname(hostname, 100); printf( Self host name is %s\n, hostname); } 39

40 Internet Time Client Listing (6) else /* Assume name is a valid symbolic host name */ strcpy( hostname, name); /* Now obtain address information from database */ hoststruct = gethostbyname(hostname); if ( hoststruct == NULL ) return(0); /* Not Found */ /* Extract the IP Address from the hostent structure */ hostnode = ( struct in_addr* ) hoststruct->h_addr; /* Display a readable version for fun */ printf( Internet Address=%s\n, inet_ntoa(*hostnode)); } return ( hostnode->s_addr ); /* Return IP address */ 40

41 Internet Time Client Listing (7) readtime( fd ) int fd; { char str[200]; /* Line buffer */ printf( The time on the target port is ); while( readline(fd,str) ) /* Read lines until end of input */ printf( %s\n, str); /* Echo line from server to user */ } /***************************************************/ readline( fd, str ) int fd; char* str; /* Read a single line terminated by a new line */ { int n; 41

42 Internet Time Client Listing (8) do /* Read characters until NULL or end of input */ { n = read(fd, str, 1); /* Read one character */ } while( n>0 && *str++!= \n ) ; } return ( n>0 ); /* Return false if end of input */ 42

43 Analyzing the Source Code Internet Clients The procedure for creating an Internet client is the same as that for creating an AF_UNIX client, Internet socket address structure is of the type struct sockaddr_in and has four fields: sin_family, the domain of the socket, which should be set to AF_INET sin_port, the port number, which is 13 in this case sin_port, the 32-bit IP number sin_zero, which is padding and is not set 43

44 Analyzing the Source Code promptforinetaddress() gets the host s name from the user and then invokes nametoaddr() to convert into an IP address. If the user enters a string starting with a digit, inet_addr() is invoked to perform the conversion. Library Call: in_addr_t inet_addr(const char* string) inet_addr() returns the 32-bit IP address that corresponds to the A.B.C.D-format string. The IP address is in network-byte order. 44

45 Analyzing the Source Code Network-byte order a host-neutral ordering of bytes in the IP address. This ordering is necessary, since regular byte ordering can differ from machine to machine, which would make IP addresses nonportable. If the string doesn t start with a digit, the next step is to see if it s s, which signifies the local host. The name of the local host is obtained by gethostname(), which works as follows: System Call: int gethostname( char* name, int namelen ) gethostname() sets the character array pointed to by name of length namelen to a NULL-terminated string equal to the local host s name. 45

46 Analyzing the Source Code Once the symbolic name of the host is determined, the next stage is to look it up in the network-host file, /etc/hosts. This task is performed by gethostbyname(), which works like this: Library Call : struct hostent* gethostbyname( const char* name ) gethostbyname() searches the /etc/hosts file and returns a pointer to a hostent structure that describes the file entry associated with the string name. If name is not found in the /etc/hosts file, NULL is returned. 46

47 Analyzing the Source Code The hostent structure has several fields, but the only one we re interested in is a field of type ( struct in_addr*) called h_addr. This field contains the host s associated IP number in a subfield called s_addr. Before returning this IP number, the program displays a string description of the IP address by calling inetntoa() Library Call: char* inet_ntoa( struct in_addr address ) inet_ntoa() takes a structure of type in_addr as its argument and returns a pointer to a string that describes the address in the format A.B.C.D. 47

48 Analyzing the Source Code Once the IP address inetaddress has been determined, the client s socket address fields are filled by (lines 37 to 40): bzero((char*)&serverinetaddress, sizeof(serverinetaddress)); serverinetaddress.sin_family = AF_INET; /* Use Internet */ serverinetaddress.sin_addr.s_addr = inetaddress; /* IP */ serverinetaddress.sin_port = htons(daytime_port); bzero() clears the socket address structure s contents before its fields are assigned: Library Call: void bzero(void* buffer, size_t length) bzero() fills the array buffer or size length with zeroes( ASCII NULL). 48

49 Analyzing the Source Code The bzero() call had its origins in the Berkeley version of UNIX. System V s equivalent is memset() : Library Call: void memset(void* buffer, int value, size_t length) memset() fills the array buffer of size length with the value of value. Like the IP address, the port number is also converted to a networkbyte ordering by htons(), which works like this: 49

50 Analyzing the Source Code Like the IP address, the port number is also converted to a networkbyte ordering by htons(), which works like this: Library Call: in_addr_t htonl(in_addr_t hostlong) in_port_t htons(in_port_t hostshort) in_addr_t ntohl(in_addr_t networklong) in_port_t ntohs(in_port_t networkshort) Each of these functions performs a conversion between a host-format number and a network-format number. For example, htonl() returns the network-format equivalent of the host-format unsigned long hostlong, and ntohs() returns the host-format equivalent of the networkformat unsigned short networkshort. 50

51 Analyzing the Source Code The final step is to create the client socket and attempt the connection. The code for this task is almost the same as that for AF_UNIX sockets: clientfd = socket( AF_INET, SOCK_STREAM, DEFAULT_PROTOCOL); do /* Loop until a connection is made with the server */ { result = connect( clientfd, serversockaddrptr, serverlen ); if ( result == -1 ) sleep(1); /* Try again in 1 second */ } while ( result == - 1 ); 51

52 Internet Servers Constructing an Internet server is actually pretty easy. The sin_family, sin_port, and sin_zero fields of the socket_address structure should be filled in as they were in the client example. The only difference is that the s_addr field should be set to the network-byte-ordered value of the constant INADDR_ANY, which means accept any incoming client requests. The following example of how to create a server socket address is a slightly modified version of some code taken from the Internet shell program that ends this chapter: int serverfd; /* Server socket */ struct sockaddr_in serverinetaddress; /* Server Internet address */ struct sockaddr* serversockaddrptr; /* Pointer to server address */ struct sockaddr_in clientinetaddress; /* Client Internet address */ 52

53 Internet Servers struct scokaddr* clientsockaddrptr; /* Pointer to client address */ int port=13; /* Set to the port that you wish to serve */ int serverlen; /* Length of address structure */ serverfd = socket(af_inet, SOCK_STREAM, DEFAULT_PROTOCOL); /* Create */ serverlen = sizeof(serverinetaddress); /* Length of structure */ bzero((char*) &serverinetaddress, serverlen); /* Clear structure */ serverinetaddress.sin_family = AF_INET; /* Internet domain */ serverinetaddress.sin_addr.s_addr = htonl(inaddr_any); /* Accept all */ serverinetaddress.sin_port = htons(port); /* Server port number */ 53

54 Internet Servers When the address is created, the socket is bound to the address, and its queue size is specified in the usual way: serversockaddrptr = (struct sockaddr*) &serverinetaddress; bind( serverfd, serversockaddrptr, serverlen); listen(serverfd, 5); The final step is to accept client connections. When a successful connection is made, the client socket address is filled with the client s IP address and a new file descriptor is returned: clientlen = sizeof( clientinetaddress ); clientsockaddrptr = ( struct sockaddr* ) clientinetaddress; clientfd = accept(serverfd, clientsockaddrptr, &clientlen); an Internet server s code is very similar to that of an AF_UNIX server. 54

55 Shared Memory Sharing a segment of memory is a straightforward and intuitive method of allowing two processes on the same machine to share data. Accessing a shared memory segment is the fasted form of IPC, since no data has to copied or sent anywhere else. some of the common system calls used to allocate and use shared memory segments in System V-based versions of UNIX are: shmget(), which allocates a shared memory segment and returns the segment ID number shmat(), which attaches a shared memory segment to the virtual address space of the calling process shmdt(), which detaches an attached segment from the address space shmctl(), which allows you to modify attributes associated with the shared memory segment( e.g., access permissions ) 55

Tutorial on Socket Programming

Tutorial on Socket Programming Tutorial on Socket Programming Computer Networks - CSC 458 Department of Computer Science Seyed Hossein Mortazavi (Slides are mainly from Monia Ghobadi, and Amin Tootoonchian, ) 1 Outline Client- server

More information

Introduction to Socket Programming Part I : TCP Clients, Servers; Host information

Introduction to Socket Programming Part I : TCP Clients, Servers; Host information Introduction to Socket Programming Part I : TCP Clients, Servers; Host information Keywords: sockets, client-server, network programming-socket functions, OSI layering, byte-ordering Outline: 1.) Introduction

More information

Unix Network Programming

Unix Network Programming Introduction to Computer Networks Polly Huang EE NTU http://cc.ee.ntu.edu.tw/~phuang phuang@cc.ee.ntu.edu.tw Unix Network Programming The socket struct and data handling System calls Based on Beej's Guide

More information

NS3 Lab 1 TCP/IP Network Programming in C

NS3 Lab 1 TCP/IP Network Programming in C NS3 Lab 1 TCP/IP Network Programming in C Dr Colin Perkins School of Computing Science University of Glasgow http://csperkins.org/teaching/ns3/ 13/14 January 2015 Introduction The laboratory exercises

More information

Socket Programming. Srinidhi Varadarajan

Socket Programming. Srinidhi Varadarajan Socket Programming Srinidhi Varadarajan Client-server paradigm Client: initiates contact with server ( speaks first ) typically requests service from server, for Web, client is implemented in browser;

More information

Socket Programming. Kameswari Chebrolu Dept. of Electrical Engineering, IIT Kanpur

Socket Programming. Kameswari Chebrolu Dept. of Electrical Engineering, IIT Kanpur Socket Programming Kameswari Chebrolu Dept. of Electrical Engineering, IIT Kanpur Background Demultiplexing Convert host-to-host packet delivery service into a process-to-process communication channel

More information

Network Programming with Sockets. Anatomy of an Internet Connection

Network Programming with Sockets. Anatomy of an Internet Connection Network Programming with Sockets Anatomy of an Internet Connection Client socket address 128.2.194.242:51213 socket address 208.216.181.15:80 Client Connection socket pair (128.2.194.242:51213, 208.216.181.15:80)

More information

Porting applications & DNS issues. socket interface extensions for IPv6. Eva M. Castro. ecastro@dit.upm.es. dit. Porting applications & DNS issues UPM

Porting applications & DNS issues. socket interface extensions for IPv6. Eva M. Castro. ecastro@dit.upm.es. dit. Porting applications & DNS issues UPM socket interface extensions for IPv6 Eva M. Castro ecastro@.upm.es Contents * Introduction * Porting IPv4 applications to IPv6, using socket interface extensions to IPv6. Data structures Conversion functions

More information

Socket Programming. Request. Reply. Figure 1. Client-Server paradigm

Socket Programming. Request. Reply. Figure 1. Client-Server paradigm Socket Programming 1. Introduction In the classic client-server model, the client sends out requests to the server, and the server does some processing with the request(s) received, and returns a reply

More information

Introduction to Socket programming using C

Introduction to Socket programming using C Introduction to Socket programming using C Goal: learn how to build client/server application that communicate using sockets Vinay Narasimhamurthy S0677790@sms.ed.ac.uk CLIENT SERVER MODEL Sockets are

More information

TCP/IP - Socket Programming

TCP/IP - Socket Programming TCP/IP - Socket Programming jrb@socket.to.me Jim Binkley 1 sockets - overview sockets simple client - server model look at tcpclient/tcpserver.c look at udpclient/udpserver.c tcp/udp contrasts normal master/slave

More information

Lab 4: Socket Programming: netcat part

Lab 4: Socket Programming: netcat part Lab 4: Socket Programming: netcat part Overview The goal of this lab is to familiarize yourself with application level programming with sockets, specifically stream or TCP sockets, by implementing a client/server

More information

CSE 333 SECTION 6. Networking and sockets

CSE 333 SECTION 6. Networking and sockets CSE 333 SECTION 6 Networking and sockets Goals for Today Overview of IP addresses Look at the IP address structures in C/C++ Overview of DNS Write your own (short!) program to do the domain name IP address

More information

IT304 Experiment 2 To understand the concept of IPC, Pipes, Signals, Multi-Threading and Multiprocessing in the context of networking.

IT304 Experiment 2 To understand the concept of IPC, Pipes, Signals, Multi-Threading and Multiprocessing in the context of networking. Aim: IT304 Experiment 2 To understand the concept of IPC, Pipes, Signals, Multi-Threading and Multiprocessing in the context of networking. Other Objective of this lab session is to learn how to do socket

More information

ELEN 602: Computer Communications and Networking. Socket Programming Basics

ELEN 602: Computer Communications and Networking. Socket Programming Basics 1 ELEN 602: Computer Communications and Networking Socket Programming Basics A. Introduction In the classic client-server model, the client sends out requests to the server, and the server does some processing

More information

Implementing Network Software

Implementing Network Software Implementing Network Software Outline Sockets Example Process Models Message Buffers Spring 2007 CSE 30264 1 Sockets Application Programming Interface (API) Socket interface socket : point where an application

More information

Socket Programming in C/C++

Socket Programming in C/C++ September 24, 2004 Contact Info Mani Radhakrishnan Office 4224 SEL email mradhakr @ cs. uic. edu Office Hours Tuesday 1-4 PM Introduction Sockets are a protocol independent method of creating a connection

More information

INTRODUCTION UNIX NETWORK PROGRAMMING Vol 1, Third Edition by Richard Stevens

INTRODUCTION UNIX NETWORK PROGRAMMING Vol 1, Third Edition by Richard Stevens INTRODUCTION UNIX NETWORK PROGRAMMING Vol 1, Third Edition by Richard Stevens Read: Chapters 1,2, 3, 4 Communications Client Example: Ex: TCP/IP Server Telnet client on local machine to Telnet server on

More information

Writing a C-based Client/Server

Writing a C-based Client/Server Working the Socket Writing a C-based Client/Server Consider for a moment having the massive power of different computers all simultaneously trying to compute a problem for you -- and still being legal!

More information

UNIX. Sockets. mgr inż. Marcin Borkowski

UNIX. Sockets. mgr inż. Marcin Borkowski UNIX Sockets Introduction to Sockets Interprocess Communication channel: descriptor based two way communication can connect processes on different machines Three most typical socket types (colloquial names):

More information

BSD Sockets Interface Programmer s Guide

BSD Sockets Interface Programmer s Guide BSD Sockets Interface Programmer s Guide Edition 6 B2355-90136 HP 9000 Networking E0497 Printed in: United States Copyright 1997 Hewlett-Packard Company. Legal Notices The information in this document

More information

Computer Networks Network architecture

Computer Networks Network architecture Computer Networks Network architecture Saad Mneimneh Computer Science Hunter College of CUNY New York - Networks are like onions - They stink? - Yes, no, they have layers Shrek and Donkey 1 Introduction

More information

Programmation Systèmes Cours 9 UNIX Domain Sockets

Programmation Systèmes Cours 9 UNIX Domain Sockets Programmation Systèmes Cours 9 UNIX Domain Sockets Stefano Zacchiroli zack@pps.univ-paris-diderot.fr Laboratoire PPS, Université Paris Diderot 2013 2014 URL http://upsilon.cc/zack/teaching/1314/progsyst/

More information

Network Programming with Sockets. Process Management in UNIX

Network Programming with Sockets. Process Management in UNIX Network Programming with Sockets This section is a brief introduction to the basics of networking programming using the BSD Socket interface on the Unix Operating System. Processes in Unix Sockets Stream

More information

Hostnames. HOSTS.TXT was a bottleneck. Once there was HOSTS.TXT. CSCE515 Computer Network Programming. Hierarchical Organization of DNS

Hostnames. HOSTS.TXT was a bottleneck. Once there was HOSTS.TXT. CSCE515 Computer Network Programming. Hierarchical Organization of DNS Hostnames CSCE 515: Computer Network Programming ------ Address Conversion Function and DNS RFC 1034, RFC 1035 Wenyuan Xu http://www.cse..edu/~wyxu/ce515f07.html Department of Computer Science and Engineering

More information

Application Architecture

Application Architecture A Course on Internetworking & Network-based Applications CS 6/75995 Internet-based Applications & Systems Design Kent State University Dept. of Science LECT-2 LECT-02, S-1 2 Application Architecture Today

More information

Lecture 17. Process Management. Process Management. Process Management. Inter-Process Communication. Inter-Process Communication

Lecture 17. Process Management. Process Management. Process Management. Inter-Process Communication. Inter-Process Communication Process Management Lecture 17 Review February 25, 2005 Program? Process? Thread? Disadvantages, advantages of threads? How do you identify processes? How do you fork a child process, the child process

More information

Elementary Name and Address Conversions

Elementary Name and Address Conversions Elementary Name and Address Conversions Domain name system gethostbyname Function RES_USE_INET6 resolver option gethostbyname2 Function and IPv6 support gethostbyaddr Function uname and gethostname Functions

More information

Elementary Name and Address. Conversions

Elementary Name and Address. Conversions Elementary Name and Address Domain name system Conversions gethostbyname Function RES_USE_INET6 resolver option gethostbyname2 Function and IPv6 support gethostbyaddr Function uname and gethostname Functions

More information

The POSIX Socket API

The POSIX Socket API The POSIX Giovanni Agosta Piattaforme Software per la Rete Modulo 2 G. Agosta The POSIX Outline Sockets & TCP Connections 1 Sockets & TCP Connections 2 3 4 G. Agosta The POSIX TCP Connections Preliminaries

More information

VMCI Sockets Programming Guide VMware ESX/ESXi 4.x VMware Workstation 7.x VMware Server 2.0

VMCI Sockets Programming Guide VMware ESX/ESXi 4.x VMware Workstation 7.x VMware Server 2.0 VMware ESX/ESXi 4.x VMware Workstation 7.x VMware Server 2.0 This document supports the version of each product listed and supports all subsequent versions until the document is replaced by a new edition.

More information

Interprocess Communication Message Passing

Interprocess Communication Message Passing Interprocess Communication Message Passing IPC facility provides two operations: send(message) message size fixed or variable receive(message) If P and Q wish to communicate, they need to: establish a

More information

Session NM059. TCP/IP Programming on VMS. Geoff Bryant Process Software

Session NM059. TCP/IP Programming on VMS. Geoff Bryant Process Software Session NM059 TCP/IP Programming on VMS Geoff Bryant Process Software Course Roadmap Slide 160 NM055 (11:00-12:00) Important Terms and Concepts TCP/IP and Client/Server Model Sockets and TLI Client/Server

More information

UNIX Sockets. COS 461 Precept 1

UNIX Sockets. COS 461 Precept 1 UNIX Sockets COS 461 Precept 1 Clients and Servers Client program Running on end host Requests service E.g., Web browser Server program Running on end host Provides service E.g., Web server GET /index.html

More information

System Calls and Standard I/O

System Calls and Standard I/O System Calls and Standard I/O Professor Jennifer Rexford http://www.cs.princeton.edu/~jrex 1 Goals of Today s Class System calls o How a user process contacts the Operating System o For advanced services

More information

An Introductory 4.4BSD Interprocess Communication Tutorial

An Introductory 4.4BSD Interprocess Communication Tutorial PSD:20-1 An Introductory 4.4BSD Interprocess Communication Tutorial Stuart Sechrest Computer Science Research Group Computer Science Division Department of Electrical Engineering and Computer Science University

More information

System Calls Related to File Manipulation

System Calls Related to File Manipulation KING FAHD UNIVERSITY OF PETROLEUM AND MINERALS Information and Computer Science Department ICS 431 Operating Systems Lab # 12 System Calls Related to File Manipulation Objective: In this lab we will be

More information

System calls. Problem: How to access resources other than CPU

System calls. Problem: How to access resources other than CPU System calls Problem: How to access resources other than CPU - Disk, network, terminal, other processes - CPU prohibits instructions that would access devices - Only privileged OS kernel can access devices

More information

Client / Server Programming with TCP/IP Sockets

Client / Server Programming with TCP/IP Sockets Client / Server Programming with TCP/IP Sockets Author: Rajinder Yadav Date: Sept 9, 2007 Revision: Mar 11, 2008 Web: http://devmentor.org Email: rajinder@devmentor.org Table of Content Networks... 2 Diagram

More information

Sources: On the Web: Slides will be available on:

Sources: On the Web: Slides will be available on: C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,

More information

SMTP-32 Library. Simple Mail Transfer Protocol Dynamic Link Library for Microsoft Windows. Version 5.2

SMTP-32 Library. Simple Mail Transfer Protocol Dynamic Link Library for Microsoft Windows. Version 5.2 SMTP-32 Library Simple Mail Transfer Protocol Dynamic Link Library for Microsoft Windows Version 5.2 Copyright 1994-2003 by Distinct Corporation All rights reserved Table of Contents 1 Overview... 5 1.1

More information

DESIGN AND IMPLEMENT AND ONLINE EXERCISE FOR TEACHING AND DEVELOPMENT OF A SERVER USING SOCKET PROGRAMMING IN C

DESIGN AND IMPLEMENT AND ONLINE EXERCISE FOR TEACHING AND DEVELOPMENT OF A SERVER USING SOCKET PROGRAMMING IN C DESIGN AND IMPLEMENT AND ONLINE EXERCISE FOR TEACHING AND DEVELOPMENT OF A SERVER USING SOCKET PROGRAMMING IN C Elena Ruiz Gonzalez University of Patras University of Granada ERASMUS STUDENT:147 1/100

More information

Networks. Inter-process Communication. Pipes. Inter-process Communication

Networks. Inter-process Communication. Pipes. Inter-process Communication Networks Mechanism by which two processes exchange information and coordinate activities Inter-process Communication process CS 217 process Network 1 2 Inter-process Communication Sockets o Processes can

More information

Implementing and testing tftp

Implementing and testing tftp CSE123 Spring 2013 Term Project Implementing and testing tftp Project Description Checkpoint: May 10, 2013 Due: May 29, 2013 For this project you will program a client/server network application in C on

More information

A Client-Server Transaction. Systemprogrammering 2006 Föreläsning 8 Network Programming. Hardware Org of a Network Host.

A Client-Server Transaction. Systemprogrammering 2006 Föreläsning 8 Network Programming. Hardware Org of a Network Host. Systemprogrammering 2006 Föreläsning 8 Network Programming Topics -server programming model A -Server Transaction Every network application is based on the client-server model: A server process and one

More information

Networks class CS144 Introduction to Computer Networking Goal: Teach the concepts underlying networks Prerequisites:

Networks class CS144 Introduction to Computer Networking Goal: Teach the concepts underlying networks Prerequisites: CS144 Introduction to Computer Networking Instructors: Philip Levis and David Mazières CAs: Juan Batiz-Benet, Behram Mistree, Hariny Murli, Matt Sparks, and Tony Wu Section Leader: Aki Kobashi cs144-staff@scs.stanford.edu

More information

Packet Sniffing and Spoofing Lab

Packet Sniffing and Spoofing Lab SEED Labs Packet Sniffing and Spoofing Lab 1 Packet Sniffing and Spoofing Lab Copyright c 2014 Wenliang Du, Syracuse University. The development of this document is/was funded by the following grants from

More information

1 Operating Systems Prof. Dr. Marc H. Scholl DBIS U KN Summer Term 2009. IPC may often be used for both

1 Operating Systems Prof. Dr. Marc H. Scholl DBIS U KN Summer Term 2009. IPC may often be used for both Intended Schedule V. IPC: Inter-Process Communication Date Lecture Hand out Submission 0 20.04. Introduction to Operating Systems Course registration 1 27.04. Systems Programming using C (File Subsystem)

More information

Application Development with TCP/IP. Brian S. Mitchell Drexel University

Application Development with TCP/IP. Brian S. Mitchell Drexel University Application Development with TCP/IP Brian S. Mitchell Drexel University Agenda TCP/IP Application Development Environment Client/Server Computing with TCP/IP Sockets Port Numbers The TCP/IP Application

More information

Review of Previous Lecture

Review of Previous Lecture Review of Previous Lecture Principles of app layer protocols clients and servers app requirements Web and HTTP FTP Some slides are in courtesy of J. Kurose and K. Ross Announcement All got partners and

More information

Communication Networks. Introduction & Socket Programming Yuval Rochman

Communication Networks. Introduction & Socket Programming Yuval Rochman Communication Networks Introduction & Socket Programming Yuval Rochman Administration Staff Lecturer: Prof. Hanoch Levy hanoch AT cs tau Office hours: by appointment Teaching Assistant: Yuval Rochman yuvalroc

More information

IBM i Version 7.2. Programming Socket programming IBM

IBM i Version 7.2. Programming Socket programming IBM IBM i Version 7.2 Programming Socket programming IBM IBM i Version 7.2 Programming Socket programming IBM Note Before using this information and the product it supports, read the information in Notices

More information

OS: IPC I. Cooperating Processes. CIT 595 Spring 2010. Message Passing vs. Shared Memory. Message Passing: Unix Pipes

OS: IPC I. Cooperating Processes. CIT 595 Spring 2010. Message Passing vs. Shared Memory. Message Passing: Unix Pipes Cooperating Processes Independent processes cannot affect or be affected by the execution of another process OS: IPC I CIT 595 Spring 2010 Cooperating process can affect or be affected by the execution

More information

This tutorial has been designed for everyone interested in learning the data exchange features of Unix Sockets.

This tutorial has been designed for everyone interested in learning the data exchange features of Unix Sockets. About the Tutorial Sockets are communication points on the same or different computers to exchange data. Sockets are supported by Unix, Windows, Mac, and many other operating systems. The tutorial provides

More information

Network Programming. Chapter 11. 11.1 The Client-Server Programming Model

Network Programming. Chapter 11. 11.1 The Client-Server Programming Model Chapter 11 Network Programming Network applications are everywhere. Any time you browse the Web, send an email message, or pop up an X window, you are using a network application. Interestingly, all network

More information

Overview. Socket Programming. Using Ports to Identify Services. UNIX Socket API. Knowing What Port Number To Use. Socket: End Point of Communication

Overview. Socket Programming. Using Ports to Identify Services. UNIX Socket API. Knowing What Port Number To Use. Socket: End Point of Communication Overview Socket Programming EE 122: Intro to Communication Networks Vern Paxson TAs: Lisa Fowler, Daniel Killebrew, Jorge Ortiz Socket Programming: how applications use the network Sockets are a C-language

More information

transmission media and network topologies client/server architecture layers, protocols, and sockets

transmission media and network topologies client/server architecture layers, protocols, and sockets Network Programming 1 Computer Networks transmission media and network topologies client/server architecture layers, protocols, and sockets 2 Network Programming a simple client/server interaction the

More information

ICT SEcurity BASICS. Course: Software Defined Radio. Angelo Liguori. SP4TE lab. angelo.liguori@uniroma3.it

ICT SEcurity BASICS. Course: Software Defined Radio. Angelo Liguori. SP4TE lab. angelo.liguori@uniroma3.it Course: Software Defined Radio ICT SEcurity BASICS Angelo Liguori angelo.liguori@uniroma3.it SP4TE lab 1 Simple Timing Covert Channel Unintended information about data gets leaked through observing the

More information

IPC. Semaphores were chosen for synchronisation (out of several options).

IPC. Semaphores were chosen for synchronisation (out of several options). IPC Two processes will use shared memory to communicate and some mechanism for synchronise their actions. This is necessary because shared memory does not come with any synchronisation tools: if you can

More information

Best practices in IPv6 enabled networking software development. <mauro@deepspace6.net>

Best practices in IPv6 enabled networking software development. <mauro@deepspace6.net> Best practices in IPv6 enabled networking software development 1 The IPv6 Protocol 1 New version of the Internet Protocol Devised by IETF to replace IPv4 It solves all the problems of IPv4 Address space

More information

How To Write On A Non-Blocking File On A Thumbtongue (Windows) (Windows 2) (Macintosh) (Amd64) (Apple) (Powerpoint) (Networking) (Unix) (Program) (

How To Write On A Non-Blocking File On A Thumbtongue (Windows) (Windows 2) (Macintosh) (Amd64) (Apple) (Powerpoint) (Networking) (Unix) (Program) ( Using TCP Through Sockets David Mazières Revised by Frank Dabek and Eric Petererson 1 Introduction This document provides an introduction to using sockets on Unix systems with a focus on asynchronous I/O.

More information

CSI 402 Lecture 13 (Unix Process Related System Calls) 13 1 / 17

CSI 402 Lecture 13 (Unix Process Related System Calls) 13 1 / 17 CSI 402 Lecture 13 (Unix Process Related System Calls) 13 1 / 17 System Calls for Processes Ref: Process: Chapter 5 of [HGS]. A program in execution. Several processes are executed concurrently by the

More information

Shared Memory Segments and POSIX Semaphores 1

Shared Memory Segments and POSIX Semaphores 1 Shared Memory Segments and POSIX Semaphores 1 Alex Delis delis -at+ pitt.edu October 2012 1 Acknowledgements to Prof. T. Stamatopoulos, M. Avidor, Prof. A. Deligiannakis, S. Evangelatos, Dr. V. Kanitkar

More information

Programming guidelines on transition to IPv6

Programming guidelines on transition to IPv6 Programming guidelines on transition to IPv6 Tomás P. de Miguel and Eva M. Castro tmiguel@dit.upm.es eva@gsyc.escet.urjc.es Department of Telematic Systems Engineering (DIT) Technical University of Madrid

More information

Informatica e Sistemi in Tempo Reale

Informatica e Sistemi in Tempo Reale Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 25, 2010 G. Lipari (Scuola Superiore Sant Anna)

More information

Concurrent Server Design Alternatives

Concurrent Server Design Alternatives CSCE 515: Computer Network Programming ------ Advanced Socket Programming Wenyuan Xu Concurrent Server Design Alternatives Department of Computer Science and Engineering University of South Carolina Ref:

More information

Generalised Socket Addresses for Unix Squeak 3.9 11

Generalised Socket Addresses for Unix Squeak 3.9 11 Generalised Socket Addresses for Unix Squeak 3.9 11 Ian Piumarta 2007 06 08 This document describes several new SocketPlugin primitives that allow IPv6 (and arbitrary future other) address formats to be

More information

The C Programming Language course syllabus associate level

The C Programming Language course syllabus associate level TECHNOLOGIES The C Programming Language course syllabus associate level Course description The course fully covers the basics of programming in the C programming language and demonstrates fundamental programming

More information

Software changes for Website and Application IPv6 Readiness

Software changes for Website and Application IPv6 Readiness Software changes for Website and Application IPv6 Readiness Ahmed Abu-Abed, P.Eng. Tamkien Systems ahmed@tamkien.com 1 Agenda Introduction Enabling Website IPv6 and Forum Certification Intro to Socket

More information

CHAPTER 7. E-Mailing with CGI

CHAPTER 7. E-Mailing with CGI CHAPTER 7 E-Mailing with CGI OVERVIEW One of the most important tasks of any CGI program is ultimately to let someone know that something has happened. The most convenient way for users is to have this

More information

Outline. Review. Inter process communication Signals Fork Pipes FIFO. Spotlights

Outline. Review. Inter process communication Signals Fork Pipes FIFO. Spotlights Outline Review Inter process communication Signals Fork Pipes FIFO Spotlights 1 6.087 Lecture 14 January 29, 2010 Review Inter process communication Signals Fork Pipes FIFO Spotlights 2 Review: multithreading

More information

Unix System Calls. Dept. CSIE 2006.12.25

Unix System Calls. Dept. CSIE 2006.12.25 Unix System Calls Gwan-Hwan Hwang Dept. CSIE National Taiwan Normal University 2006.12.25 UNIX System Overview UNIX Architecture Login Name Shells Files and Directories File System Filename Pathname Working

More information

Linux Driver Devices. Why, When, Which, How?

Linux Driver Devices. Why, When, Which, How? Bertrand Mermet Sylvain Ract Linux Driver Devices. Why, When, Which, How? Since its creation in the early 1990 s Linux has been installed on millions of computers or embedded systems. These systems may

More information

Department of Electrical Engineering and Computer Science MASSACHUSETTS INSTITUTE OF TECHNOLOGY. 6.828 Operating System Engineering: Fall 2005

Department of Electrical Engineering and Computer Science MASSACHUSETTS INSTITUTE OF TECHNOLOGY. 6.828 Operating System Engineering: Fall 2005 Department of Electrical Engineering and Computer Science MASSACHUSETTS INSTITUTE OF TECHNOLOGY 6.828 Operating System Engineering: Fall 2005 Quiz II Solutions Average 84, median 83, standard deviation

More information

CS 213, Fall 2000 Lab Assignment L5: Logging Web Proxy Assigned: Nov. 28, Due: Mon. Dec. 11, 11:59PM

CS 213, Fall 2000 Lab Assignment L5: Logging Web Proxy Assigned: Nov. 28, Due: Mon. Dec. 11, 11:59PM CS 213, Fall 2000 Lab Assignment L5: Logging Web Proxy Assigned: Nov. 28, Due: Mon. Dec. 11, 11:59PM Jason Crawford (jasonc@cs.cmu.edu) is the lead person for this assignment. Introduction A web proxy

More information

Java Programming: Sockets in Java

Java Programming: Sockets in Java Java Programming: Sockets in Java Manuel Oriol May 10, 2007 1 Introduction Network programming is probably one of the features that is most used in the current world. As soon as people want to send or

More information

Windows Socket Programming & IPv6 Translation Middleware

Windows Socket Programming & IPv6 Translation Middleware Windows Socket Programming IPv6 Translation Middleware Dr. Whai-En Chen VoIP and IPv6 Laboratory Research Assistant Professor Dept. of Computer Science and Information Engineering National Chiao Tung University

More information

A Client Server Transaction. Introduction to Computer Systems 15 213/18 243, fall 2009 18 th Lecture, Nov. 3 rd

A Client Server Transaction. Introduction to Computer Systems 15 213/18 243, fall 2009 18 th Lecture, Nov. 3 rd A Client Server Transaction Introduction to Computer Systems 15 213/18 243, fall 2009 18 th Lecture, Nov. 3 rd 4. Client handles response Client process 1. Client sends request 3. Server sends response

More information

Domain Name System (1)! gethostbyname (2)! gethostbyaddr (2)!

Domain Name System (1)! gethostbyname (2)! gethostbyaddr (2)! Lecture 5 Overview Last Lecture Socket Options and elementary UDP sockets This Lecture Name and address conversions & IPv6 Source: Chapter 11 Next Lecture Multicast Source: Chapter 12 1 Domain Name System

More information

Illustration 1: Diagram of program function and data flow

Illustration 1: Diagram of program function and data flow The contract called for creation of a random access database of plumbing shops within the near perimeter of FIU Engineering school. The database features a rating number from 1-10 to offer a guideline

More information

Client-server Sockets

Client-server Sockets Client-server Sockets 1 How to Write a Network Based Program (Using Microchip's TCP/IP Stack) A network based program that uses the Client-server architecture must create at least two separate programs,

More information

1 Abstract Data Types Information Hiding

1 Abstract Data Types Information Hiding 1 1 Abstract Data Types Information Hiding 1.1 Data Types Data types are an integral part of every programming language. ANSI-C has int, double and char to name just a few. Programmers are rarely content

More information

TCP/IP Sockets in C. Practical Guide for Programmers

TCP/IP Sockets in C. Practical Guide for Programmers TCP/IP Sockets in C Practical Guide for Programmers The Morgan Kaufmann Practical Guides Series Series Editor: Michael J. Donahoo TCP/IP Sockets in C: Practical Guide for Programmers Michael J. Donahoo

More information

TFTP Usage and Design. Diskless Workstation Booting 1. TFTP Usage and Design (cont.) CSCE 515: Computer Network Programming ------ TFTP + Errors

TFTP Usage and Design. Diskless Workstation Booting 1. TFTP Usage and Design (cont.) CSCE 515: Computer Network Programming ------ TFTP + Errors CSCE 515: Computer Network Programming ------ TFTP + Errors Wenyuan Xu Department of Computer Science and Engineering University of South Carolina TFTP Usage and Design RFC 783, 1350 Transfer files between

More information

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++ Answer the following 1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++ 2) Which data structure is needed to convert infix notations to postfix notations? Stack 3) The

More information

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C Embedded Systems A Review of ANSI C and Considerations for Embedded C Programming Dr. Jeff Jackson Lecture 2-1 Review of ANSI C Topics Basic features of C C fundamentals Basic data types Expressions Selection

More information

KATRAGADDA INNOVATIVE TRUST FOR EDUCATION NETWORK PROGRAMMING. Notes prepared by D. Teja Santosh, Assistant Professor, KPES, Shabad, R.R. District.

KATRAGADDA INNOVATIVE TRUST FOR EDUCATION NETWORK PROGRAMMING. Notes prepared by D. Teja Santosh, Assistant Professor, KPES, Shabad, R.R. District. KATRAGADDA INNOVATIVE TRUST FOR EDUCATION NETWORK PROGRAMMING 2 P age N E T W O R K P R O G R A M M I N G INTRODUCTION UNIT-I Introduction and TCP/IP When writing programs that communicate across a computer

More information

Goal: learn how to build client/server application that communicate using sockets. An interface between application and network

Goal: learn how to build client/server application that communicate using sockets. An interface between application and network Socket programming Goal: learn how to build client/server application that communicate using sockets Socket API introduced in BSD4.1 UNIX, 1981 explicitly created, used, released by apps client/server

More information

REAL TIME OPERATING SYSTEM PROGRAMMING-II: II: Windows CE, OSEK and Real time Linux. Lesson-12: Real Time Linux

REAL TIME OPERATING SYSTEM PROGRAMMING-II: II: Windows CE, OSEK and Real time Linux. Lesson-12: Real Time Linux REAL TIME OPERATING SYSTEM PROGRAMMING-II: II: Windows CE, OSEK and Real time Linux Lesson-12: Real Time Linux 1 1. Real Time Linux 2 Linux 2.6.x Linux is after Linus Torvalds, father of the Linux operating

More information

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C 1 An essential part of any embedded system design Programming 2 Programming in Assembly or HLL Processor and memory-sensitive

More information

Project 1: Implement a simple hosts framework using UNIX TCP Sockets to demonstrate the concept of Mobile Agents

Project 1: Implement a simple hosts framework using UNIX TCP Sockets to demonstrate the concept of Mobile Agents Project 1: Implement a simple hosts framework using UNIX TCP Sockets to demonstrate the concept of Mobile Agents Due date: October 15 (Monday), 2007 Requirements This exercise should be done individually.

More information

How To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint)

How To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint) TN203 Porting a Program to Dynamic C Introduction Dynamic C has a number of improvements and differences compared to many other C compiler systems. This application note gives instructions and suggestions

More information

Operating Systems Design 16. Networking: Sockets

Operating Systems Design 16. Networking: Sockets Operating Systems Design 16. Networking: Sockets Paul Krzyzanowski pxk@cs.rutgers.edu 1 Sockets IP lets us send data between machines TCP & UDP are transport layer protocols Contain port number to identify

More information

Java Interview Questions and Answers

Java Interview Questions and Answers 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write and compile the java

More information

Division of Informatics, University of Edinburgh

Division of Informatics, University of Edinburgh CS1Bh Lecture Note 20 Client/server computing A modern computing environment consists of not just one computer, but several. When designing such an arrangement of computers it might at first seem that

More information

Applications and Services. DNS (Domain Name System)

Applications and Services. DNS (Domain Name System) Applications and Services DNS (Domain Name Service) File Transfer Protocol (FTP) Simple Mail Transfer Protocol (SMTP) Malathi Veeraraghavan Distributed database used to: DNS (Domain Name System) map between

More information

Glossary of Object Oriented Terms

Glossary of Object Oriented Terms Appendix E Glossary of Object Oriented Terms abstract class: A class primarily intended to define an instance, but can not be instantiated without additional methods. abstract data type: An abstraction

More information

Introduction. dnotify

Introduction. dnotify Introduction In a multi-user, multi-process operating system, files are continually being created, modified and deleted, often by apparently unrelated processes. This means that any software that needs

More information

RIOT-Lab. How to use RIOT in the IoT-Lab. Oliver "Oleg" Hahm. November 7, 2014 INRIA. O. Hahm (INRIA) RIOT-Lab November 7, 2014 1 / 29

RIOT-Lab. How to use RIOT in the IoT-Lab. Oliver Oleg Hahm. November 7, 2014 INRIA. O. Hahm (INRIA) RIOT-Lab November 7, 2014 1 / 29 RIOT-Lab How to use RIOT in the IoT-Lab Oliver "Oleg" Hahm INRIA November 7, 2014 O. Hahm (INRIA) RIOT-Lab November 7, 2014 1 / 29 Agenda 1 Start the RIOT 2 Using RIOT 3 Writing an Application for RIOT

More information

Building a Multi-Threaded Web Server

Building a Multi-Threaded Web Server Building a Multi-Threaded Web Server In this lab we will develop a Web server in two steps. In the end, you will have built a multi-threaded Web server that is capable of processing multiple simultaneous

More information