Piotr Mielecki Ph. D.

Size: px
Start display at page:

Download "Piotr Mielecki Ph. D."

Transcription

1 Piotr Mielecki Ph. D.

2 Building blocks of client-server applications: Client, Server, Middleware. Simple client-server application: Version 1.0 non-multitasking server, client s requests queued and serviced according to FIFO strategy. Version 2.0 multitasking server, client s requests are serviced parallel. Version 2.5 multitasking server which can be installed as UNIX / Linux system service (daemon).

3 Client: runs the client side of the application, runs on the OS that provides an user interface and that can access distributed services, wherever they may be, the client can also run a component of the Distributed System Management (DSM) element: DSM agents run on every node in the client/server network, managing workstation collects information from all its agents on the network and displays it, the managing workstation can also instruct its agents to perform actions on its behalf.

4 Server: runs the server side of the application, the server application typically runs on top of some shrink-wrapped server software package, the five contending server platforms for creating client/server applications are: SQL database severs, Transaction Processing Monitors to ensure that the transaction processes completely or, if an error occurs, to take appropriate actions (in most of cases integrated with database servers), groupware servers, object servers see Component Object Model (COM) for example, web servers, the server side depends on the OS to interface with the middleware building block, it may be a simple agent or a shared object database etc.

5 Middleware: runs on both the client and server sides of an application, middleware is the nervous system of the client/server infrastructure, this can also have the Distributed System Management (DSM) component.

6 Client Middleware Server User interface Web browser DSM OS Service specific HTTP ODBC Mail TxRPC ORB Distributed System Management (DSM) SNMP CMIP Tivoli / ORB Network Operating System (NOS) Directory Services Security Distributed File System RPC Messaging Peer-to-Peer Transport stack NetBIOS TCP/IP IPX/SPX SNA SQL DBMS TP Monitor Groupware Objects Web server DSM OS

7 Server waits for message from client and sends back acknowledgement after receiving. Client sends message to server and waits for acknowledgement. Both use UNIX TCP/IP sockets as middleware. When server receives SHUTDOWN message quits (server recognizes a command from client we can call it Application level protocol ). Message Acknowledgement Sends a text message to server Waits for message from client

8 Server program (v. 1.0): Create socket Listen on socket NO Connection requested YES Receive message Send acknowledgement Accept connection Provide service Close connection Close socket YES SHUTDOWN command NO Quit

9 Server v. 1.0 code, part 1: #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #define BUFF_LEN 256 // Length of the message buffer int main(int argc, char *argv[]) int sockfd, consockfd; // Socket file descriptors struct sockaddr_in serv_addr, cli_addr; socklen_t clilen; char cli_addr_str[inet_addrstrlen]; char buffer[buff_len]; const char *ack_message = "Message acknowledged."; int n; if (argc < 3) // Server s IP and port given in command line fprintf(stderr,"command: %s <address> <port>\n", argv[0]); clilen = sizeof(cli_addr); // Set length of client address

10 Server v. 1.0 code, part 2: // Step 1. Create the Internet socket (SOCK_STREAM and 0 means TCP): sockfd = socket( AF_INET, SOCK_STREAM, 0 ); if (sockfd < 0) fprintf(stderr,"server ERROR: socket opening failed.\n"); // Initialize address of the server in serv_addr: bzero( (char *) &serv_addr, sizeof(serv_addr) ); serv_addr.sin_family = AF_INET; // Function inet_pton() gets IP address from C character string and // stores it in sin_addr field of sockaddr_in type structure. // Use this function rather instead obsolete inet_addr() which doesn't // support IPv6. In this example AF_INET means IPv4. inet_pton( AF_INET, argv[1], &(serv_addr.sin_addr) ); // Function htons() converts port number in host byte order // (depends on host computer architecture) to a port number // in network byte order (standardized). serv_addr.sin_port = htons( atoi(argv[2]) );

11 Server v. 1.0 code, part 3: // Step 2. Bind the socket to address - sets the value of file // descriptor (handle). // Typecasting is required to fit sockaddr_in type structure // to general sockaddr type. if ( bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0 ) fprintf(stderr,"server ERROR: binding failed, the port is in use.\n"); // Step 3. Listen on socket pointed by its handle. // The 2nd parameter is size of the backlog queue - the number // of connections that can be waiting while the process is handling // a particular connection. Typicaly 5 is the maximum value. listen( sockfd, 5 );

12 Server v. 1.0 code, part 4: // Step 4. Accept connections from clients and perform operations. do // Function accept() blocks process till any connection from // client comes. consockfd = accept( sockfd, (struct sockaddr *) &cli_addr, &clilen ); // The returned new handle to socket represents this particular // connection and should be used for servicing this connection. if (consockfd < 0) fprintf(stderr,"server ERROR: accept failed.\n"); // Function inet_ntop() gets address from sin_addr field of sockaddr_in // type structure and stores it to C character string. inet_ntop(af_inet, &(cli_addr.sin_addr), cli_addr_str, INET_ADDRSTRLEN); printf("[server] Connection accepted with client %s port %d\n", cli_addr_str, ntohs(cli_addr.sin_port));

13 Server v. 1.0 code, part 5: bzero( buffer, BUFF_LEN ); n = read( consockfd, buffer, BUFF_LEN ); // Read from the socket. if (n < 0) fprintf(stderr,"server ERROR: reading from socket failed.\n"); printf("[server] Message from client: Length = %d Content = %s\n", strlen(buffer), buffer); // Send acknowledgement message write to socket: n = write( consockfd, ack_message, strlen(ack_message) ); if (n < 0) fprintf(stderr,"server ERROR: writing to socket failed.\n"); close( consockfd ); // Close socket descriptor used by connection. while ( strcmp( buffer, "SHUTDOWN" )!= 0 ); // Until SHUTDOWN command

14 Server v. 1.0 code, part 6: // Exiting the server program: close( sockfd ); // Close socket descriptor used for listening. printf("[server] - Shutting down.\n"); return 0;

15 Client program (v. 1.0): Create socket Connect to server Send message Receive acknowledgement Close socket Quit

16 Client v. 1.0 code, part 1: #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> #define BUFF_LEN 256 // Length of the message buffer int main(int argc, char *argv[]) int sockfd, n; struct sockaddr_in serv_addr; struct hostent *server; char buffer[buff_len]; if (argc < 3) // Server s IP address and port given in command line. fprintf(stderr,"command: %s <address> <port>\n", argv[0]);

17 Client v. 1.0 code, part 2: // Step 1. Get host address for IP or URL given in argv[1]: server = gethostbyname( argv[1] ); if (server == NULL) fprintf(stderr,"error: server host not found.\n"); // Step 2. Create server address from gethostbyname() result: bzero((char *) &serv_addr, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; bcopy( (char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr, server->h_length ); serv_addr.sin_port = htons( atoi(argv[2]) ); // Step 3. Create the Internet socket (SOCK_STREAM and 0 means TCP): sockfd = socket( AF_INET, SOCK_STREAM, 0 ); if (sockfd < 0) fprintf(stderr,"error: socket opening failed.\n");

18 Client v. 1.0 code, part 3: // Step 4. Connect to server - operation compatible with accept() // on server side: if (connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) fprintf(stderr,"error: connecting to server failed.\n"); // Input message text to the buffer: bzero( buffer, BUFF_LEN ); printf("message FOR server: "); fgets( buffer, BUFF_LEN, stdin ); // Replace end of line character(s) with NULL terminator: for( n = 0; n < strlen(buffer); n++ ) if ( buffer[n] == '\n' buffer[n] == '\r' ) buffer[n] = '\0';

19 Client v. 1.0 code, part 4: // Step 5. Send the message to server via socket: n = write( sockfd, buffer, strlen(buffer) ); if (n < 0) fprintf(stderr,"error: writing to socket failed.\n"); // Step 6. Read acknowledge message from server via socket: bzero( buffer, BUFF_LEN ); n = read( sockfd, buffer, BUFF_LEN ); if (n < 0) fprintf(stderr,"error: reading from socket failed.\n"); printf( "Message FROM server: %s\n", buffer ); // Step 7. Close Internet socket and connection: close( sockfd ); return 0;

20 Client program (v. 1.5): Create socket Connect to server Send message Receive acknowledgement Close socket YES QUIT command NO Quit YES SHUTDOWN command NO

21 Client v. 1.5 code, part 1: #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> #define BUFF_LEN 256 // Length of the message buffer int main(int argc, char *argv[]) int sockfd, n; struct sockaddr_in serv_addr; struct hostent *server; char buffer[buff_len]; if (argc < 3) // Server s IP address and port given in command line. fprintf(stderr,"command: %s <address> <port>\n", argv[0]);

22 Client v. 1.5 code, part 2: // Step 1. Get host address for IP or URL given in argv[1]: server = gethostbyname( argv[1] ); if (server == NULL) fprintf(stderr,"error: server host not found.\n"); // Step 2. Create server address from gethostbyname() result: bzero((char *) &serv_addr, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; bcopy( (char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr, server->h_length ); serv_addr.sin_port = htons( atoi(argv[2]) ); do // Client loop begining (doesn t exist in v. 1.0). // Step 3. Create the Internet socket: sockfd = socket( AF_INET, SOCK_STREAM, 0 ); if (sockfd < 0) fprintf(stderr,"error: socket opening failed.\n");

23 Client v. 1.5 code, part 3: // Step 4. Connect to server - operation compatible with accept() // on server side: if (connect(sockfd,(struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) fprintf(stderr,"error: connecting to server failed.\n"); // Input message text to the buffer: bzero( buffer, BUFF_LEN ); printf("message FOR server: "); fgets( buffer, BUFF_LEN, stdin ); // Replace end of line character(s) with NULL terminator: for( n = 0; n < strlen(buffer); n++ ) if ( buffer[n] == '\n' buffer[n] == '\r' ) buffer[n] = '\0'; // Check the exit conditions (doesn t exist in v. 1.0): if ( strcmp(buffer, "QUIT") == 0 strcmp(buffer, "SHUTDOWN") == 0 ) next_msg = 0; else next_msg = 1;

24 Client v. 1.5 code, part 4: // Step 5. Send the message to server via socket: n = write( sockfd, buffer, strlen(buffer) ); if (n < 0) fprintf(stderr,"error: writing to socket failed.\n"); // Step 6. Read acknowledge message from server via socket: bzero( buffer, BUFF_LEN ); n = read( sockfd, buffer, BUFF_LEN ); if (n < 0) fprintf(stderr,"error: reading from socket failed.\n"); printf( "Message FROM server: %s\n", buffer ); // Step 7. Close Internet socket and connection: close( sockfd ); while ( next_msg!= 0 ); // Client loop end. printf( "Quiting.\n" ); return 0;

25 Server program (v. 2.0): Create socket NO Listen on socket Connection requested PARENT fork() YES CHILD Accept connection Close connection Perform service 1 Exit child process NO QUIT command YES Close socket Close connection Quit parent process YES SHUTDOWN command NO 1 Exit child process

26 Server v. 2.0 code, part 1: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <sys/wait.h> #include <signal.h> #define BUFF_LEN 256 // Length of the message buffer. int sockfd; // Parent socket handle declared as public // to be available for SIGQUIT handler.

27 Server v. 2.0 code, part 2: // Handler for SIGCHLD signal raised up by each child process on exit. // Parent process reads all information about exiting child to avoid // zombie creation. void sigchld_handler( int signo ) pid_t PID; int status; do PID = waitpid( -1, &status, WNOHANG ); while ( PID!= -1 ); signal( SIGCHLD, sigchld_handler ); // Handler for SIGQUIT signal used to quit parent process. void sigquit_handler( int signo ) close( sockfd ); printf("[server] Shutting down.\n"); exit( 0 );

28 Server v. 2.0 code, part 3: #define BUFF_LEN 256 // Length of the message buffer int main(int argc, char *argv[]) int consockfd; struct sockaddr_in serv_addr, cli_addr; socklen_t clilen; char cli_addr_str[inet_addrstrlen]; unsigned short cli_port; char buffer[buff_len]; const char *ack_message = "Message acknowledged."; pid_t PID, PPID; int n; if (argc < 3) fprintf(stderr,"command: %s <address> <port>\n", argv[0]); signal( SIGCHLD, sigchld_handler ); clilen = sizeof(cli_addr); // Set SIGCHLD signal handler.

29 Server v. 2.0 code, part 4: // Step 1. Create the Internet socket (SOCK_STREAM and 0 means TCP): sockfd = socket( AF_INET, SOCK_STREAM, 0 ); if (sockfd < 0) fprintf(stderr,"server ERROR: socket opening failed.\n"); // Initialize address of the server in serv_addr: bzero( (char *) &serv_addr, sizeof(serv_addr) ); serv_addr.sin_family = AF_INET; // Function inet_pton() gets IP address from C character string and // stores it in sin_addr field of sockaddr_in type structure. // Use this function rather instead obsolete inet_addr() which doesn't // support IPv6. In this example AF_INET means IPv4. inet_pton( AF_INET, argv[1], &(serv_addr.sin_addr) ); // Function htons() converts port number in host byte order // (depends on host computer architecture) to a port number // in network byte order (standardized). serv_addr.sin_port = htons( atoi(argv[2]) );

30 Server v. 2.0 code, part 5: // Step 2. Bind the socket to address - sets the value of file // descriptor (handle). // Typecasting is required to fit sockaddr_in type structure // to general sockaddr type. if ( bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0 ) fprintf(stderr,"server ERROR: binding failed, the port is in use.\n"); // Step 3. Listen on socket pointed by its handle. // The 2nd parameter is size of the backlog queue - the number // of connections that can be waiting while the process is handling // a particular connection. Typicaly 5 is the maximum value. listen( sockfd, 5 );

31 Server v. 2.0 code, part 6: // Step 4. Accept connections from clients and perform operations. do // Server main loop begining. consockfd = accept( sockfd, (struct sockaddr *) &cli_addr, &clilen ); if (consockfd < 0) fprintf(stderr,"server ERROR: accept failed.\n"); inet_ntop(af_inet, &(cli_addr.sin_addr), cli_addr_str, INET_ADDRSTRLEN); printf("[server] Connection accepted with client %s port %d\n", cli_addr_str, ntohs(cli_addr.sin_port)); // Create child process for servicing client s request: if( (PID = fork()) == -1 ) // fork() error. close( consockfd ); fprintf(stderr,"server ERROR: Creating new process failed.\n"); continue; else if( PID > 0 ) // Parent process. close( consockfd ); // Close the parent's copy of handle. signal( SIGQUIT, sigquit_handler ); // Set SIGQUIT signal handler. continue;

32 Server v. 2.0 code, part 7: // Child process starts here. PPID = getppid(); do // Session loop session with client. bzero( buffer, BUFF_LEN ); n = read( consockfd, buffer, BUFF_LEN ); // Read message from client. if (n < 0) fprintf(stderr,"server ERROR: reading from socket failed.\n"); // Replace end of line character(s) with terminator: for( n = 0; n < strlen(buffer); n++ ) if ( buffer[n] == '\n' buffer[n] == '\r' ) buffer[n] = '\0'; printf("[server] Message from client [%s %d]: %s\n", cli_addr_str, cli_port, buffer); n = write( consockfd, ack_message, strlen(ack_message) ); if (n < 0) fprintf(stderr,"server ERROR: writing to socket failed.\n");

33 Server v. 2.0 code, part 8: if ( strcmp(buffer, "SHUTDOWN") == 0 ) printf("[server] Shutting down.\n"); kill( PPID, SIGQUIT ); // Send SIGQUIT signal to parent process. break; while ( strcmp( buffer, "QUIT" )!= 0 ); // Session loop end. printf("[server] Session with client [%s %d] quits.\n", cli_addr_str, cli_port); close( consockfd ); exit( 0 ); // Exit child process (session with client). while ( 1 ); // Server main loop end.

34 Client program (v. 2.0): Create socket Connect to server Send message Receive acknowledgement YES QUIT command NO Close socket YES SHUTDOWN command NO Quit

35 Client v. 2.0 code, part 1: #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> #define BUFF_LEN 256 // Length of the message buffer int main(int argc, char *argv[]) int sockfd, n, next_msg; struct sockaddr_in serv_addr; struct hostent *server; char buffer[buff_len]; if (argc < 3) fprintf(stderr,"command: %s <address> <port>\n", argv[0]);

36 Client v. 2.0 code, part 2: // Step 1. Get host address for IP or URL given in argv[1]: server = gethostbyname( argv[1] ); if (server == NULL) fprintf(stderr,"error: server host not found.\n"); // Step 2. Create server address from gethostbyname() result: bzero((char *) &serv_addr, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; bcopy( (char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr, server->h_length ); serv_addr.sin_port = htons( atoi(argv[2]) ); // Step 3. Create the Internet socket: sockfd = socket( AF_INET, SOCK_STREAM, 0 ); if (sockfd < 0) fprintf(stderr,"error: socket opening failed.\n");

37 Client v. 2.0 code, part 3: // Step 4. Connect to server - operation compatible with accept() // on server side: if (connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) fprintf(stderr,"error: connecting to server failed.\n"); do // Client main loop session with active TCP connection. // Input message text to the buffer. bzero( buffer, BUFF_LEN ); printf("message FOR server: "); fgets( buffer, BUFF_LEN, stdin ); // Replace end of line character(s) with terminator: for( n = 0; n < strlen(buffer); n++ ) if ( buffer[n] == '\n' buffer[n] == '\r' ) buffer[n] = '\0'; // Check the exit conditions: if ( strcmp(buffer, "QUIT") == 0 strcmp(buffer, "SHUTDOWN") == 0 ) next_msg = 0; else next_msg = 1;

38 Client v. 2.0 code, part 4: // Step 5. Send the message to server via socket: n = write( sockfd, buffer, strlen(buffer) ); if (n < 0) fprintf(stderr,"error: writing to socket failed.\n"); // Step 6. Read acknowledge message from server via socket: bzero( buffer, BUFF_LEN ); n = read( sockfd, buffer, BUFF_LEN ); if (n < 0) fprintf(stderr,"error: reading from socket failed.\n"); printf( "Message FROM server: %s\n", buffer ); while ( next_msg!= 0 ); printf( "Quiting.\n" ); // Step 7. Close Internet socket and connection (session): close( sockfd ); return 0;

39 Server v. 2.5 (daemon) code, part 1: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <sys/wait.h> #include <signal.h> #define BUFF_LEN 256 // Length of the message buffer. int sockfd; // Parent socket handle declared as public // to be available for SIGQUIT handler.

40 Server v. 2.5 code, part 2: // Handler for SIGCHLD signal raised up by each child process on exit. // Parent process reads all information about exiting child to avoid // zombie creation. void sigchld_handler( int signo ) pid_t PID; int status; do PID = waitpid( -1, &status, WNOHANG ); while ( PID!= -1 ); signal( SIGCHLD, sigchld_handler ); // Handler for SIGQUIT signal used to quit parent process. void sigquit_handler( int signo ) close( sockfd ); printf("[server] Shutting down.\n"); exit( 0 );

41 Server v. 2.5 code, part 3: #define BUFF_LEN 256 // Length of the message buffer int main(int argc, char *argv[]) int consockfd; struct sockaddr_in serv_addr, cli_addr; socklen_t clilen; char cli_addr_str[inet_addrstrlen]; unsigned short cli_port; char buffer[buff_len]; const char *ack_message = "Message acknowledged."; pid_t PID, PPID; int n; if (argc < 3) fprintf(stderr,"command: %s <address> <port>\n", argv[0]);

42 Server v. 2.5 code, part 4: // Function daemon() "cuts-off" the process from its parent, // that means process becomes intentionaly created orphan // and can run without user's session. // In fact it's a kind of fork() which kills parent process. // // Prototype: int daemon(int nochdir, int noclose); // nochdir - if set to 0 process changes its working // directory to / // noclose - if set to 0 process redirects standard input, // standard output and standard error to /dev/null daemon( 0, 1 ); signal( SIGCHLD, sigchld_handler ); // Set SIGCHLD signal handler. clilen = sizeof(cli_addr);

43 Server v. 2.5 code, part 5: // Step 1. Create the Internet socket (SOCK_STREAM and 0 means TCP): sockfd = socket( AF_INET, SOCK_STREAM, 0 ); if (sockfd < 0) fprintf(stderr,"server ERROR: socket opening failed.\n"); // Initialize address of the server in serv_addr: bzero( (char *) &serv_addr, sizeof(serv_addr) ); serv_addr.sin_family = AF_INET; // Function inet_pton() gets IP address from C character string and // stores it in sin_addr field of sockaddr_in type structure. // Use this function rather instead obsolete inet_addr() which doesn't // support IPv6. In this example AF_INET means IPv4. inet_pton( AF_INET, argv[1], &(serv_addr.sin_addr) ); // Function htons() converts port number in host byte order // (depends on host computer architecture) to a port number // in network byte order (standardized). serv_addr.sin_port = htons( atoi(argv[2]) );

44 Server v. 2.5 code, part 6: // Step 2. Bind the socket to address - sets the value of file // descriptor (handle). // Typecasting is required to fit sockaddr_in type structure // to general sockaddr type. if ( bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0 ) fprintf(stderr,"server ERROR: binding failed, the port is in use.\n"); // Step 3. Listen on socket pointed by its handle. // The 2nd parameter is size of the backlog queue - the number // of connections that can be waiting while the process is handling // a particular connection. Typicaly 5 is the maximum value. listen( sockfd, 5 );

45 Server v. 2.5 code, part 7: // Step 4. Accept connections from clients and perform operations. do // Server main loop begining. consockfd = accept( sockfd, (struct sockaddr *) &cli_addr, &clilen ); if (consockfd < 0) fprintf(stderr,"server ERROR: accept failed.\n"); inet_ntop(af_inet, &(cli_addr.sin_addr), cli_addr_str, INET_ADDRSTRLEN); printf("[server] Connection accepted with client %s port %d\n", cli_addr_str, ntohs(cli_addr.sin_port)); // Create child process for servicing client s request: if( (PID = fork()) == -1 ) // fork() error. close( consockfd ); fprintf(stderr,"server ERROR: Creating new process failed.\n"); continue; else if( PID > 0 ) // Parent process. close( consockfd ); // Close the parent's copy of handle. signal( SIGQUIT, sigquit_handler ); // Set SIGQUIT signal handler. continue;

46 Server v. 2.5 code, part 8: // Child process starts here. PPID = getppid(); do // Session loop session with client. bzero( buffer, BUFF_LEN ); n = read( consockfd, buffer, BUFF_LEN ); // Read message from client. if (n < 0) fprintf(stderr,"server ERROR: reading from socket failed.\n"); // Replace end of line character(s) with terminator: for( n = 0; n < strlen(buffer); n++ ) if ( buffer[n] == '\n' buffer[n] == '\r' ) buffer[n] = '\0'; printf("[server] Message from client [%s %d]: %s\n", cli_addr_str, cli_port, buffer); n = write( consockfd, ack_message, strlen(ack_message) ); if (n < 0) fprintf(stderr,"server ERROR: writing to socket failed.\n");

47 Server v. 2.5 code, part 9: if ( strcmp(buffer, "SHUTDOWN") == 0 ) printf("[server] Shutting down.\n"); kill( PPID, SIGQUIT ); // Send SIGQUIT signal to parent process. break; while ( strcmp( buffer, "QUIT" )!= 0 ); // Session loop end. printf("[server] Session with client [%s %d] quits.\n", cli_addr_str, cli_port); close( consockfd ); exit( 0 ); // Exit child process (session with client). while ( 1 ); // Server main loop end.

UNIX Network Programming. Overview of Socket API Network Programming Basics

UNIX Network Programming. Overview of Socket API Network Programming Basics UNIX Network Programming Overview of Socket API Network Programming Basics 1 Client-Server Model Client Machine A Network Server Machine B Web browser and server FTP client and server Telnet client and

More information

CS307 Operating Systems Processes

CS307 Operating Systems Processes CS307 Processes Fan Wu Department of Computer Science and Engineering Shanghai Jiao Tong University Spring 2018 Process Concept Process a program in execution An operating system executes a variety of

More information

Processes. Process Concept. The Process. The Process (Cont.) Process Control Block (PCB) Process State

Processes. Process Concept. The Process. The Process (Cont.) Process Control Block (PCB) Process State CS307 Process Concept Process a program in execution Processes An operating system executes a variety of programs: Batch system jobs Time-shared systems user programs or tasks All these activities are

More information

Network Programming Worksheet 2. Simple TCP Clients and Servers on *nix with C.

Network Programming Worksheet 2. Simple TCP Clients and Servers on *nix with C. Simple TCP Clients and Servers on *nix with C. Aims. This worksheet introduces a simple client and a simple server to experiment with a daytime service. It shows how telnet can be used to test the server.

More information

Sockets. Dong-kun Shin Embedded Software Laboratory Sungkyunkwan University Embedded Software Lab.

Sockets. Dong-kun Shin Embedded Software Laboratory Sungkyunkwan University  Embedded Software Lab. 1 Sockets Dong-kun Shin Embedded Software Laboratory Sungkyunkwan University http://nyx.skku.ac.kr Internet Connections (1) 2 Connection Clients and servers communicate by sending streams of bytes over

More information

Introduction to Client-Server Model

Introduction to Client-Server Model Preview Introduction to Client-Server Model Motivation of Client-Server Model Terminologies and Concepts in Client-Server Model Connectionless vs. Connection-Oriented Stateless vs. Stateful Server Identify

More information

Unix Network Programming Chapter 4. Elementary TCP Sockets 광운대학교컴퓨터과학과 정보통신연구실 석사과정안중현

Unix Network Programming Chapter 4. Elementary TCP Sockets 광운대학교컴퓨터과학과 정보통신연구실 석사과정안중현 Unix Network Programming Chapter 4. Elementary TCP Sockets 광운대학교컴퓨터과학과 정보통신연구실 석사과정안중현 4.1 Introduction A Time line of the typical scenario that takes place between a TCP client and server. Describes the

More information

Hyo-bong Son Computer Systems Laboratory Sungkyunkwan University

Hyo-bong Son Computer Systems Laboratory Sungkyunkwan University Sockets Hyo-bong Son (proshb@csl.skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Client-Server Model Most network application is based on the client-server model: A server

More information

Sockets. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Sockets. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Sockets Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Internet Connections (1) Connection Clients and servers communicate by sending streams of

More information

PA #2 Reviews. set_name, get_name, del_name. Questions? Will be modified after PA #4 ~

PA #2 Reviews. set_name, get_name, del_name. Questions? Will be modified after PA #4 ~ Sockets Prof. Jin-Soo Kim( jinsookim@skku.edu) TA Dong-Yun Lee(dylee@csl.skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu PA #2 Reviews set_name, get_name, del_name Will

More information

Sockets. Dong-kun Shin Embedded Software Laboratory Sungkyunkwan University Embedded Software Lab.

Sockets. Dong-kun Shin Embedded Software Laboratory Sungkyunkwan University  Embedded Software Lab. 1 Sockets Dong-kun Shin Embedded Software Laboratory Sungkyunkwan University http://nyx.skku.ac.kr Echo Client (1) 2 #include #include #include #include

More information

CS 3516: Computer Networks

CS 3516: Computer Networks Welcome to CS 3516: Prof. Yanhua Li Time: 9:00am 9:50am M, T, R, and F Location: AK219 Fall 2018 A-term 1 Some slides are originally from the course materials of the textbook Computer Networking: A Top

More information

CS321: Computer Networks Socket Programming

CS321: Computer Networks Socket Programming CS321: Computer Networks Socket Programming Dr. Manas Khatua Assistant Professor Dept. of CSE IIT Jodhpur E-mail: manaskhatua@iitj.ac.in Socket Programming It shows how the network application programs

More information

Lecture 3 Overview! Last Lecture! TCP/UDP and Sockets introduction!

Lecture 3 Overview! Last Lecture! TCP/UDP and Sockets introduction! Lecture 3 Overview! Last Lecture! TCP/UDP and Sockets introduction! This Lecture! Elementary TCP sockets! TCP Client-Server example! Source: Stevens book(chapters 4,5), Comer s book (Chapters 20, 21)!

More information

ECE 435 Network Engineering Lecture 2

ECE 435 Network Engineering Lecture 2 ECE 435 Network Engineering Lecture 2 Vince Weaver http://web.eece.maine.edu/~vweaver vincent.weaver@maine.edu 31 August 2017 Announcements Homework 1 will be posted. Will be on website, will announce

More information

CS321: Computer Networks Introduction to Application Layer

CS321: Computer Networks Introduction to Application Layer CS321: Computer Networks Introduction to Application Layer Dr. Manas Khatua Assistant Professor Dept. of CSE IIT Jodhpur E-mail: manaskhatua@iitj.ac.in Basic Application layer provides services to the

More information

Experiential Learning Workshop on Basics of Socket Programming

Experiential Learning Workshop on Basics of Socket Programming Experiential Learning Workshop on Basics of Socket June 28, 2018 Dr. Ram P Rustagi Professor, CSE Dept KSIT, Bangalore rprustagi@ksit.edu.in Resources https://rprustagi.com/elnt/experiential- Learning.html

More information

The BSD UNIX Socket Interface (CS 640 Lecture) Assignment 1. Interprocess Communication (IPC) Work Individually (no groups)

The BSD UNIX Socket Interface (CS 640 Lecture) Assignment 1. Interprocess Communication (IPC) Work Individually (no groups) The BSD UNIX Socket Interface (CS 640 Lecture) Assignment 1 Work Individually (no groups) Due Date: in class, Monday, September 19 Robert T Olsen olsen@cswiscedu 7390CS Office Hours: 3-5T, 11-12F - exception

More information

NETWORK AND SYSTEM PROGRAMMING. I/O Multiplexing: select and poll function

NETWORK AND SYSTEM PROGRAMMING. I/O Multiplexing: select and poll function NETWORK AND SYSTEM PROGRAMMING LAB 15 I/O Multiplexing: select and poll function 15.1 objectives What is a Concurrent server Use of Select System call Use of Poll System call 15.2 What is concurrent server?

More information

ECE 435 Network Engineering Lecture 2

ECE 435 Network Engineering Lecture 2 ECE 435 Network Engineering Lecture 2 Vince Weaver http://web.eece.maine.edu/~vweaver vincent.weaver@maine.edu 6 September 2018 Announcements Homework 1 will be posted. Will be on website, will announce

More information

Elementary TCP Sockets

Elementary TCP Sockets Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens Distributed Computer Systems 1 socket interface Application 1 Application 2 socket interface user kernel user kernel

More information

Embedded System Design

Embedded System Design Embedded System Design Lecture 9 Jaeyong Chung Robust Systems Laboratory Incheon National University Inter-process Commnucation (IPC) Chung EPC6071 2 Inter-process Commnucation (IPC) A set of methods for

More information

CS4514 B08 HELP Session 1

CS4514 B08 HELP Session 1 CS4514 B08 HELP Session 1 Presented by Choong-Soo Lee clee01@cs.wpi.edu CS4514 TCP/IP Socket Programming Outline Project 1 Overview Unix Network Programming TCP Client TCP Server Processing commands How

More information

ECE322 Systems Programming Project 2: Networking with Matrix Multiplication in C Grant Kimes 12/16/15

ECE322 Systems Programming Project 2: Networking with Matrix Multiplication in C Grant Kimes 12/16/15 ECE322 Systems Programming Project 2: Networking with Matrix Multiplication in C Grant Kimes 12/16/15 This project take two inputted matrices of a given size to multiply. The client sends the data to a

More information

Application Programming Interfaces

Application Programming Interfaces Application Programming Interfaces Stefan D. Bruda Winter 2018 SYSTEM CALLS Machine 1 Machine 2 Application 1 Application 3 Application 4 Application 5 Application 2 API (system functions) API (system

More information

Inter-Process Communication. Disclaimer: some slides are adopted from the book authors slides with permission 1

Inter-Process Communication. Disclaimer: some slides are adopted from the book authors slides with permission 1 Inter-Process Communication Disclaimer: some slides are adopted from the book authors slides with permission 1 Today Inter-Process Communication (IPC) What is it? What IPC mechanisms are available? 2 Inter-Process

More information

CSE 333 SECTION 8. Sockets, Network Programming

CSE 333 SECTION 8. Sockets, Network Programming CSE 333 SECTION 8 Sockets, Network Programming Overview Domain Name Service (DNS) Client side network programming steps and calls Server side network programming steps and calls dig and ncat tools Network

More information

CSE 333 SECTION 7. C++ Virtual Functions and Client-Side Network Programming

CSE 333 SECTION 7. C++ Virtual Functions and Client-Side Network Programming CSE 333 SECTION 7 C++ Virtual Functions and Client-Side Network Programming Overview Virtual functions summary and worksheet Domain Name Service (DNS) Client side network programming steps and calls dig

More information

Data and Computer Communications. Tenth Edition by William Stallings

Data and Computer Communications. Tenth Edition by William Stallings Data and Computer Communications Tenth Edition by William Stallings Data and Computer Communications, Tenth Edition by William Stallings, (c) Pearson Education - Prentice Hall, 2013 CHAPTER 2 Protocol

More information

Introduction to Socket Programming

Introduction to Socket Programming UNIT II - ELEMENTARY TCP SOCKETS Introduction to Socket Programming Introduction to Sockets Socket address Structures Byte ordering functions address conversion functions Elementary TCP Sockets socket,

More information

CSE 333 SECTION 7. Client-Side Network Programming

CSE 333 SECTION 7. Client-Side Network Programming CSE 333 SECTION 7 Client-Side Network Programming Overview Domain Name Service (DNS) Client side network programming steps and calls dig and ncat tools Network programming for the client side Recall the

More information

Semester 2, Computer Communication 352 Module 4

Semester 2, Computer Communication 352 Module 4 Page 4.1; CRICOS Number: 00301J MODULE 4 References: 1. Stevens, Fenner, Rudoff, UNIX Network Programming, vol. 1, Chapter 5. OBJECTIVE Provide detail description on TCP Client-Server Example. Discuss

More information

Week 2 Intro to the Shell with Fork, Exec, Wait. Sarah Diesburg Operating Systems CS 3430

Week 2 Intro to the Shell with Fork, Exec, Wait. Sarah Diesburg Operating Systems CS 3430 Week 2 Intro to the Shell with Fork, Exec, Wait Sarah Diesburg Operating Systems CS 3430 1 Why is the Shell Important? Shells provide us with a way to interact with the core system Executes programs on

More information

Network Socket Programming - 3 BUPT/QMUL

Network Socket Programming - 3 BUPT/QMUL Network Socket Programming - 3 BUPT/QMUL 2017-3-27 Agenda Basic concepts in NP Introduction to IP & TCP/UDP Introduction to Sockets 2 Introduction to Sockets Reviews of some helpful points Sockets interface

More information

Processes communicating. Network Communication. Sockets. Addressing processes 4/15/2013

Processes communicating. Network Communication. Sockets. Addressing processes 4/15/2013 Processes communicating Network Communication Process: program running within a host. within same host, two processes communicate using inter-process communication (defined by OS). processes in different

More information

CS 471 Operating Systems. Spring 2016 Midterm Exam Time 2 & 1/2 hours. Open Book & Notes

CS 471 Operating Systems. Spring 2016 Midterm Exam Time 2 & 1/2 hours. Open Book & Notes CS 471 Operating Systems Spring 2016 Midterm Exam Time 2 & 1/2 hours Open Book & Notes Name: Unix Login: Question 1 (20 points) A. What is the output of the following program if executed as: % Q1A Q1A.c

More information

CS4700/CS5700 Fundamentals of Computer Networking

CS4700/CS5700 Fundamentals of Computer Networking CS4700/CS5700 Fundamentals of Computer Networking Prof. Alan Mislove Lecture 3: Crash course in socket programming September 10th, 2009 Project 0 Goal: Familiarize you with socket programming in C Implement

More information

Network Socket Programming - 3 BUPT/QMUL

Network Socket Programming - 3 BUPT/QMUL Network Socket Programming - 3 BUPT/QMUL 2018-04-02 Agenda Basic concepts in NP Introduction to IP & TCP/UDP Introduction to Sockets 2 Introduction to Sockets Reviews of some helpful points Sockets interface

More information

Applications and Layered Architectures. Chapter 2 Communication Networks Leon-Garcia, Widjaja

Applications and Layered Architectures. Chapter 2 Communication Networks Leon-Garcia, Widjaja Applications and Layered Architectures Chapter 2 Communication Networks Leon-Garcia, Widjaja Network Architecture Architecture: Any design or orderly arrangement perceived by man. The goals of a network:

More information

How do we Communicate? Introduction to Unix Network Programming. What does Alice do? What does Bob do? Two simplest networking programs

How do we Communicate? Introduction to Unix Network Programming. What does Alice do? What does Bob do? Two simplest networking programs Introduction to Unix Network Programming Reference: Stevens Unix Network Programming How do we Communicate? Send a mail from Alice to Bob Bob Alice in Champaign, Bob in Hollywood Example: US Postal Service

More information

NETWORK PROGRAMMING. Instructor: Junaid Tariq, Lecturer, Department of Computer Science

NETWORK PROGRAMMING. Instructor: Junaid Tariq, Lecturer, Department of Computer Science NETWORK PROGRAMMING CSC- 341 25 Instructor: Junaid Tariq, Lecturer, Department of Computer Science 26 9 Lecture Sockets as means for inter-process communication (IPC) application layer Client Process Socket

More information

Review. Preview. Closing a TCP Connection. Closing a TCP Connection. Port Numbers 11/27/2017. Packet Exchange for TCP Connection

Review. Preview. Closing a TCP Connection. Closing a TCP Connection. Port Numbers 11/27/2017. Packet Exchange for TCP Connection Review Preview Algorithms and Issues in Client Software Design Client Architecture Identifying the Location of a Parsing an Address Argument Looking Up a Domain Name Looking Up a Well-Known Port by Name

More information

1 /* client.c - adapted from code for example client program that uses TCP */ 2 /*Modified by Vincent Chu, Winter

1 /* client.c - adapted from code for example client program that uses TCP */ 2 /*Modified by Vincent Chu, Winter 1 /* client.c - adapted from code for example client program that uses TCP */ 2 /*Modified by Vincent Chu, Winter 2004. 3 http://www.sfu.ca/~vwchu 4 chuvincent (at) gmail (dot) com 5 */ 6 7 #define closesocket

More information

Internet protocol stack. Internetworking II: Network programming. April 20, UDP vs TCP. Berkeley Sockets Interface.

Internet protocol stack. Internetworking II: Network programming. April 20, UDP vs TCP. Berkeley Sockets Interface. 15-213 Internetworking II: Network programming Berkeley sockets interface Internet protocol stack April 20, 2000 Topics client/server model Berkeley sockets TCP client and server examples UDP client and

More information

Internetworking II: Network programming. April 20, 2000

Internetworking II: Network programming. April 20, 2000 15-213 Internetworking II: Network programming Topics April 20, 2000 client/server model Berkeley sockets TCP client and server examples UDP client and server examples I/O multiplexing with select() Internet

More information

Client/Server. Networking Approach.

Client/Server. Networking Approach. Client/Server Networking Approach andrei.doncescu@laas.fr CLIENT/SERVER COMPUTING (THE WAVE OF THE FUTURE) OBJECTIVES Goal: How application programs use protocol software to communicate across networks

More information

Unix Network Programming

Unix Network Programming Introduction to Computer Networks Polly Huang EE NTU Unix Network Programming The socket struct and data handling System calls Based on Beej's Guide to Network Programming 1 The Unix Socket A file descriptor

More information

Network Communication

Network Communication Network Communication Processes communicating Process: program running within a host. q within same host, two processes communicate using inter- process communica6on (defined by OS). q processes in different

More information

The Berkeley Sockets API. Networked Systems Architecture 3 Lecture 4

The Berkeley Sockets API. Networked Systems Architecture 3 Lecture 4 The Berkeley Sockets API Networked Systems Architecture 3 Lecture 4 The Berkeley Sockets API Widely used low-level C networking API First introduced in 4.3BSD Unix Now available on most platforms: Linux,

More information

Socket Programming. CSIS0234A Computer and Communication Networks. Socket Programming in C

Socket Programming. CSIS0234A Computer and Communication Networks. Socket Programming in C 1 CSIS0234A Computer and Communication Networks Socket Programming in C References Beej's Guide to Network Programming Official homepage: http://beej.us/guide/bgnet/ Local mirror http://www.cs.hku.hk/~c0234a/bgnet/

More information

04 Elementary. Client/Server. CEN 463 Network Programming. Dr. Mostafa Hassan Dahshan. King Saud University

04 Elementary. Client/Server. CEN 463 Network Programming. Dr. Mostafa Hassan Dahshan. King Saud University CEN 463 Network Programming 04 Elementary TCP Sockets Dr. Mostafa Hassan Dahshan College of Computer and Information Sciences King Saud University Elementary TCP Client/Server 2 socket Function First function

More information

Introduction to Socket Programming

Introduction to Socket Programming Introduction to Socket Programming (Advanced Computer Networks) By Priyank Shah NET ID : pss160530 A Simple Question What are Sockets? Sockets are communication points on the same or different computers

More information

Java Basics 5 - Sockets. Manuel Oriol - May 4th, 2006

Java Basics 5 - Sockets. Manuel Oriol - May 4th, 2006 Java Basics 5 - Sockets Manuel Oriol - May 4th, 2006 Connected / Disconnected Modes Connected mode: path chosen and packets arrive all, in correct order (e.g. Phone) Disconnected mode: path not chosen

More information

CSE 333 SECTION 6. Networking and sockets

CSE 333 SECTION 6. Networking and sockets CSE 333 SECTION 6 Networking and sockets Overview Network Sockets IP addresses and IP address structures in C/C++ DNS Resolving DNS names Demos Section exercise Sockets Network sockets are network interfaces

More information

Network Programming in C: The Berkeley Sockets API. Networked Systems 3 Laboratory Sessions

Network Programming in C: The Berkeley Sockets API. Networked Systems 3 Laboratory Sessions Network Programming in C: The Berkeley Sockets API Networked Systems 3 Laboratory Sessions The Berkeley Sockets API Widely used low-level C networking API First introduced in 4.3BSD Unix Now available

More information

Message passing systems are popular because they support client-server interactions, where: clients send messages to servers requesting a server.

Message passing systems are popular because they support client-server interactions, where: clients send messages to servers requesting a server. Client-Server Model Message passing systems are popular because they support client-server interactions, where: clients send messages to servers requesting a server. servers provide services requested

More information

TCP/IP Sockets in C: Practical Guide for Programmers. Computer Chat. Internet Protocol (IP) IP Address. Transport Protocols. Ports

TCP/IP Sockets in C: Practical Guide for Programmers. Computer Chat. Internet Protocol (IP) IP Address. Transport Protocols. Ports TCP/IP Sockets in C: Practical Guide for Programmers Computer Chat! How do we make computers talk? Michael J. Donahoo Kenneth L. Calvert Morgan Kaufmann Publisher $14.95 Paperback! How are they interconnected?

More information

CS 640: Computer Networking

CS 640: Computer Networking CS 640: Computer Networking Yu-Chi Lai Lecture 3 Network Programming Topics Client-server model Sockets interface Socket primitives Example code for echoclient and echoserver Debugging With GDB Programming

More information

MSc Integrated Electronics Networks Assignment. Investigation of TCP/IP Sockets and Ports. Gavin Cameron

MSc Integrated Electronics Networks Assignment. Investigation of TCP/IP Sockets and Ports. Gavin Cameron MSc Integrated Electronics Networks Assignment Investigation of TCP/IP Sockets and Ports Gavin Cameron Introduction TCP and IP (Transmission Control Protocol / Internet Protocol) are two protocols from

More information

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 20

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 20 CS24: INTRODUCTION TO COMPUTING SYSTEMS Spring 2018 Lecture 20 LAST TIME: UNIX PROCESS MODEL Began covering the UNIX process model and API Information associated with each process: A PID (process ID) to

More information

A GENERALIZED FRAMEWORK FOR CATV TRANSMISSION ON FUTURE BISDN

A GENERALIZED FRAMEWORK FOR CATV TRANSMISSION ON FUTURE BISDN A GENERALIZED FRAMEWORK FOR CATV TRANSMISSION ON FUTURE BISDN Geng-Sheng (G.S.) Kuo Department of Information Management, National Central University Chung-Li, Taiwan 32054, R.O.C. TEL: +886 3 4263086

More information

Linux Network Programming, Part 1

Linux Network Programming, Part 1 Linux Network Programming, Part 1 http://www.linuxjournal.com/article/2333?page=0,0 Feb 01, 1998 By Ivan Griffin and John Nelson This is the first of a series of articles about how to develop networked

More information

INTEGRATED INFORMATION AND COMMUNICATION LEARNING MODEL FOR RASPBERRY Pi ENVIRONMENT

INTEGRATED INFORMATION AND COMMUNICATION LEARNING MODEL FOR RASPBERRY Pi ENVIRONMENT INTEGRATED INFORMATION AND COMMUNICATION LEARNING MODEL FOR RASPBERRY Pi ENVIRONMENT Y. J. Lee Department of Technology Education, Korea National University of Education, South Korea E-Mail: lyj@knue.ac.kr

More information

Lab 0. Yvan Petillot. Networks - Lab 0 1

Lab 0. Yvan Petillot. Networks - Lab 0 1 Lab 0 Yvan Petillot Networks - Lab 0 1 What You Will Do In This Lab. The purpose of this lab is to help you become familiar with the UNIX/LINUX on the lab network. This means being able to do editing,

More information

Introduction and Overview Socket Programming Higher-level interfaces Final thoughts. Network Programming. Samuli Sorvakko/Nixu Oy

Introduction and Overview Socket Programming Higher-level interfaces Final thoughts. Network Programming. Samuli Sorvakko/Nixu Oy Network Programming Samuli Sorvakko/Nixu Oy Telecommunications software and Multimedia Laboratory T-110.4100 Computer Networks October 16, 2008 Agenda 1 Introduction and Overview Introduction 2 Socket

More information

Network Programming in C. Networked Systems 3 Laboratory Sessions and Problem Sets

Network Programming in C. Networked Systems 3 Laboratory Sessions and Problem Sets Network Programming in C Networked Systems 3 Laboratory Sessions and Problem Sets Lab Timetable, Aims, and Objectives Teaching Week Activity 14 Introduction 15 Warm-up exercise 16 17 Web client 18 19 20

More information

ICT 6544 Distributed Systems Lecture 5

ICT 6544 Distributed Systems Lecture 5 ICT 6544 Distributed Systems Lecture 5 Hossen Asiful Mustafa Message Brokers Figure 4-21. The general organization of a message broker in a message-queuing system. IBM s WebSphere Message-Queuing System

More information

Azblink API for Sending XMPP Messages via HTTP POST

Azblink API for Sending XMPP Messages via HTTP POST Azblink API for Sending XMPP Messages via HTTP POST Abstract: This document is to describe the API of Azblink SBC for sending XMPP messages via HTTP POST. This is intended for the systems or the devices

More information

Interprocess Communication Mechanisms

Interprocess Communication Mechanisms Interprocess Communication 1 Interprocess Communication Mechanisms shared storage These mechanisms have already been covered. examples: shared virtual memory shared files processes must agree on a name

More information

Programming with TCP/IP. Ram Dantu

Programming with TCP/IP. Ram Dantu 1 Programming with TCP/IP Ram Dantu 2 Client Server Computing Although the Internet provides a basic communication service, the protocol software cannot initiate contact with, or accept contact from, a

More information

Unix-Linux 2. Unix is supposed to leave room in the process table for a superuser process that could be used to kill errant processes.

Unix-Linux 2. Unix is supposed to leave room in the process table for a superuser process that could be used to kill errant processes. Unix-Linux 2 fork( ) system call is successful parent suspended child created fork( ) returns child pid to parent fork( ) returns zero value to child; zero is the pid of the swapper/scheduler process both

More information

CSC Systems Programming Fall Lecture - XV Network Programming - I. Tevfik Ko!ar. Louisiana State University. November 9 th, 2010

CSC Systems Programming Fall Lecture - XV Network Programming - I. Tevfik Ko!ar. Louisiana State University. November 9 th, 2010 CSC 4304 - Systems Programming Fall 2010 Lecture - XV Network Programming - I Tevfik Ko!ar Louisiana State University November 9 th, 2010 1 Network Programming 2 Sockets A Socket is comprised of: a 32-bit

More information

Lecture 7. Followup. Review. Communication Interface. Socket Communication. Client-Server Model. Socket Programming January 28, 2005

Lecture 7. Followup. Review. Communication Interface. Socket Communication. Client-Server Model. Socket Programming January 28, 2005 Followup symbolic link (soft link): pathname, can be across file systems, replacement of file will be active on all symbolic links, consumes at least an inode. hard link: pointers to an inode, only in

More information

CSE 333 Lecture 16 - network programming intro

CSE 333 Lecture 16 - network programming intro CSE 333 Lecture 16 - network programming intro Hal Perkins Department of Computer Science & Engineering University of Washington Today Network programming - dive into the Berkeley / POSIX sockets API -

More information

Network programming(i) Lenuta Alboaie

Network programming(i) Lenuta Alboaie Network programming(i) Lenuta Alboaie adria@info.uaic.ro 2017 2018 Computer Network http://www.info.uaic.ro/~computernetworks 1 Content Client/server paradigm API for network programming BSD Socket Characteristics

More information

Client-server model The course that gives CMU its Zip! Network programming Nov 27, Using ports to identify services.

Client-server model The course that gives CMU its Zip! Network programming Nov 27, Using ports to identify services. 15-213 The course that gives CMU its Zip! Network programming Nov 27, 2001 Topics Client- model Sockets interface Echo and Client- model Every network application is based on the - model: Application is

More information

CS118 Discussion 1B, Week 1. Taqi Raza BUNCHE 1209B, Fridays 12:00pm to 1:50pm

CS118 Discussion 1B, Week 1. Taqi Raza BUNCHE 1209B, Fridays 12:00pm to 1:50pm CS118 Discussion 1B, Week 1 Taqi Raza BUNCHE 1209B, Fridays 12:00pm to 1:50pm 1 TA Taqi, PhD student in Computer Networking Discussion (1B): Bunche 1209, Fri 12:00 1:50 p.m. Office hours: Boelter Hall

More information

Chapter 5. TCP Client-Server

Chapter 5. TCP Client-Server Chapter 5. TCP Client-Server Example Contents Introduction TCP Echo Server TCP Echo Client Normal Startup and Termination Posix Signal Handling Handling SIGCHLD Signals Data Format and so on... 5.1 Introduction

More information

Interprocess Communication Mechanisms

Interprocess Communication Mechanisms Interprocess Communication 1 Interprocess Communication Mechanisms ffl shared storage These mechanisms have already been covered. examples: Λ shared virtual memory Λ shared files processes must agree on

More information

/* * porting from BSD to SVR4 */ #ifdef USE_BSD # include <machine/param.h> #endif

/* * porting from BSD to SVR4 */ #ifdef USE_BSD # include <machine/param.h> #endif * This is a free program sample that may be reproduced in any form. * The author's information should be retained to preserve its identity. * * Date written: January 1, 2002 * Written by: Peraphon Sophatsathit

More information

CS240: Programming in C

CS240: Programming in C CS240: Programming in C Lecture 16: Process and Signals Cristina Nita-Rotaru Lecture 16/ Fall 2013 1 Processes in UNIX UNIX identifies processes via a unique Process ID Each process also knows its parent

More information

Operating Systems, laboratory exercises. List 2.

Operating Systems, laboratory exercises. List 2. Operating Systems, laboratory exercises. List 2. Subject: Creating processes and threads with UNIX/Linux API functions. 1. Creating a process with UNIX API function. To create a new process from running

More information

A Socket Example. Haris Andrianakis & Angelos Stavrou George Mason University

A Socket Example. Haris Andrianakis & Angelos Stavrou George Mason University A Socket Example & George Mason University Everything is a file descriptor Most socket system calls operate on file descriptors Server - Quick view socket() bind() listen() accept() send(), recv() close()

More information

Introduction and Overview Socket Programming Higher-level interfaces Final thoughts. Network Programming. Samuli Sorvakko/Nixu Oy

Introduction and Overview Socket Programming Higher-level interfaces Final thoughts. Network Programming. Samuli Sorvakko/Nixu Oy Network Programming Samuli Sorvakko/Nixu Oy Telecommunications software and Multimedia Laboratory T-110.4100 Computer Networks October 9, 2006 Agenda 1 Introduction and Overview Introduction 2 Socket Programming

More information

System Programming. Process Control II

System Programming. Process Control II Content : by Dr. B. Boufama School of Computer Science University of Windsor Instructor: Dr. A. Habed adlane@cs.uwindsor.ca http://cs.uwindsor.ca/ adlane/60-256 Content Content 1 Terminating a process

More information

Announcement (1) Due date for PA3 is changed (~ next week) PA4 will also be started in the next class. Not submitted. Not scored

Announcement (1) Due date for PA3 is changed (~ next week) PA4 will also be started in the next class. Not submitted. Not scored Announcement (1) Due date for PA3 is changed (~ next week) PA4 will also be started in the next class Not submitted Not scored 1 Concurrent Programming Prof. Jin-Soo Kim( jinsookim@skku.edu) TA Sanghoon

More information

Introduction and Overview Socket Programming Lower-level stuff Higher-level interfaces Security. Network Programming. Samuli Sorvakko/Nixu Oy

Introduction and Overview Socket Programming Lower-level stuff Higher-level interfaces Security. Network Programming. Samuli Sorvakko/Nixu Oy Network Programming Samuli Sorvakko/Nixu Oy Telecommunications software and Multimedia Laboratory T-110.4100 Computer Networks October 5, 2009 Agenda 1 Introduction and Overview 2 Socket Programming 3

More information

Client software design

Client software design Client software design Stefan D. Bruda Winter 2018 A TCP CLIENT 1 Get the IP address and port number of the peer 2 Allocate a socket 3 Choose a local IP address 4 Allow TCP to choose an arbitrary, unused

More information

How to write a Measurement Telnet Server

How to write a Measurement Telnet Server How to write a Measurement Telnet Server A measurement Telnet server allows you to access remote I/Os with a standard Telnet client program. The following samples shows a way to set the LEDs of a DNP/EVA1

More information

CSE 421/521 - Operating Systems Fall 2011 Recitations. Recitation - III Networking & Concurrent Programming Prof. Tevfik Kosar. Presented by...

CSE 421/521 - Operating Systems Fall 2011 Recitations. Recitation - III Networking & Concurrent Programming Prof. Tevfik Kosar. Presented by... CSE 421/521 - Operating Systems Fall 2011 Recitations Recitation - III Networking & Concurrent Programming Prof. Tevfik Kosar Presented by... University at Buffalo September..., 2011 1 Network Programming

More information

CompSci 356: Computer Network Architectures Lecture 3: Hardware and physical links References: Chap 1.4, 1.5 of [PD] Xiaowei Yang

CompSci 356: Computer Network Architectures Lecture 3: Hardware and physical links References: Chap 1.4, 1.5 of [PD] Xiaowei Yang CompSci 356: Computer Network Architectures Lecture 3: Hardware and physical links References: Chap 1.4, 1.5 of [PD] Xiaowei Yang xwy@cs.duke.edu Overview Lab overview Application Programming Interface

More information

System Programming. Sockets: examples

System Programming. Sockets: examples Content : by Dr. B. Boufama School of Computer Science University of Windsor Instructor: Dr. A. Habed adlane@cs.uwindsor.ca http://cs.uwindsor.ca/ adlane/60-256 Content Content 1 Socket based client/server

More information

CS240: Programming in C

CS240: Programming in C CS240: Programming in C Lecture 17: Processes, Pipes, and Signals Cristina Nita-Rotaru Lecture 17/ Fall 2013 1 Processes in UNIX UNIX identifies processes via a unique Process ID Each process also knows

More information

Operating systems and concurrency - B03

Operating systems and concurrency - B03 Operating systems and concurrency - B03 David Kendall Northumbria University David Kendall (Northumbria University) Operating systems and concurrency - B03 1 / 15 Introduction This lecture gives a more

More information

Prepared by Prof. Hui Jiang Process. Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University

Prepared by Prof. Hui Jiang Process. Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University EECS3221.3 Operating System Fundamentals No.2 Process Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University How OS manages CPU usage? How CPU is used? Users use CPU to run

More information

Cracking WEP Keys Using WEPCrack

Cracking WEP Keys Using WEPCrack Appendix E Cracking WEP Keys Using WEPCrack This appendix describes an experiment to crack a WEP-protected WLAN using WEPCrack, an open-source WEP cracking tool. WEPCrack implements the RC4 weak-key attack

More information

Process. Prepared by Prof. Hui Jiang Dept. of EECS, York Univ. 1. Process in Memory (I) PROCESS. Process. How OS manages CPU usage? No.

Process. Prepared by Prof. Hui Jiang Dept. of EECS, York Univ. 1. Process in Memory (I) PROCESS. Process. How OS manages CPU usage? No. EECS3221.3 Operating System Fundamentals No.2 Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University How OS manages CPU usage? How CPU is used? Users use CPU to run programs

More information

CompSci 356: Computer Network Architectures. Lecture 3: Network Architecture Examples and Lab 1. Xiaowei Yang

CompSci 356: Computer Network Architectures. Lecture 3: Network Architecture Examples and Lab 1. Xiaowei Yang CompSci 356: Computer Network Architectures Lecture 3: Network Architecture Examples and Lab 1 Xiaowei Yang xwy@cs.duke.edu Overview The Internet Architecture OSI Network Architecture Lab 1 Released Due:

More information

Ά η η 1 (30%): Sockets. socket () bind () listen () accept () connect () read () write () close ()

Ά η η 1 (30%): Sockets. socket () bind () listen () accept () connect () read () write () close () ΗΜΥ 316 - Ε α η ια ή Ά η η 5 Υ ο οίη η Π ω ο ό ο α η αι α α ο ή sockets Ά η η 1 (30%): Sockets π α α α α α π πα π α α ω sockets Unix/Linux. Γ α α α π π α π α Server α Client π π π α έ Α π, α α απ π ω.

More information

Why a Computer Network??? Stand alone Computer. For What?

Why a Computer Network??? Stand alone Computer. For What? Computer Network Josua M Sinambela, CCNP, CCNA, CEH, CompTIA Security+ Computer Network & Security Consultant RootBrain IT Training & Consulting Email : josh@rootbrain.com Website: www.rootbrain.com 1

More information