Introduction to Network Programming Speaker: Jae Chung

Slides:



Advertisements
Similar presentations
Introduction to Sockets Jan Why do we need sockets? Provides an abstraction for interprocess communication.
Advertisements

Socket Programming Application Programming Interface.
CS3516 (B10) HELP Session 2 Presented by Lei Cao.
CS3516 B10 Help Session 1 CS3516 — TCP/IP Socket Programming Presented by Can (John) Tatar.
Sockets Programming CS144 Review Session 1 April 4, 2008 Ben Nham.
Networks: TCP/IP Socket Calls1 Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Socket Programming: a Primer Socket to me!. Feb. 23, 2001EE122, UCB2 Why does one need sockets? application network protocol sockets network.
Sockets Programming Introduction © Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid.
CS4514 B05 HELP Session 1 CS4514 – TCP/IP Socket Programming Presented by Feng Li
Programming with Berkeley Sockets Presented by Chris GauthierDickey Written by Daniel Stutzbach (I think!) for CIS 432/532 Useful References: ● man pages.
CS 311 – Lecture 18 Outline IPC via Sockets – Server side socket() bind() accept() listen() – Client side connect() Lecture 181CS Operating Systems.
Ken French HELP Session 1 CS4514. CS4514 We expect that you have had a programming course similar to 2005 before coming into this class. Programs will.
1 Tutorial on Socket Programming Computer Networks - CSC 458 Department of Computer Science Yukun Zhu (Slides are mainly from Monia Ghobadi, and Amin Tootoonchian,
Basic Socket Programming TCP/IP overview. TCP interface Reference: –UNIX Network Programming, by Richard Stevens. –UNIX man page.
CPSC 441 TUTORIAL – JANUARY 18, 2012 TA: MARYAM ELAHI INTRODUCTION TO SOCKET PROGRAMMING WITH C.
ECE 4110 – Internetwork Programming Client-Server Model.
Sockets and intro to IO multiplexing. Goals We are going to study sockets programming as means to introduce IO multiplexing problem. We will revisit socket.
TCP/IP Protocol Stack IP Device Drivers TCPUDP Application Sockets (Gate to network) TCP: –Establish connection –Maintain connection during the communication.
Socket Programming. Introduction Sockets are a protocol independent method of creating a connection between processes. Sockets can be either – Connection.
CS345 Operating Systems Φροντιστήριο Άσκησης 2. Inter-process communication Exchange data among processes Methods –Signal –Pipe –Sockets.
9/12/2015B.R1 Socket Abstraction and Interprocess Communication B.Ramamurthy CSE421.
Server Sockets: A server socket listens on a given port Many different clients may be connecting to that port Ideally, you would like a separate file descriptor.
The Application Layer Application Services (Telnet, FTP, , WWW) Reliable Stream Transport (TCP) Connectionless Packet Delivery Service (IP) Unreliable.
Lab #1: Network Programming using Sockets By J. H. Wang Nov. 28, 2011.
Socket Programming Lec 2 Rishi Kant. Review of Socket programming Decide which type of socket – stream or datagram. Based on type create socket using.
Networking Tutorial Special Interest Group for Software Engineering Luke Rajlich.
CS 158A1 1.4 Implementing Network Software Phenomenal success of the Internet: – Computer # connected doubled every year since 1981, now approaching 200.
CPSC 441 TUTORIAL – FEB 13, 2012 TA: RUITNG ZHOU UDP REVIEW.
Cli/Serv.: sockets 3/91 Client/Server Distributed Systems v Objectives –describe iterative clients and servers using the UDP protocol ,
University of Calgary – CPSC 441.  A socket is an interface between the application and the network (the lower levels of the protocol stack)  The application.
Introduction to Socket
Socket Programming Lab 1 1CS Computer Networks.
Sockets Socket = abstraction of the port concept: –Application programs request that the operating system create a socket when one is needed –O.S. returns.
Chapter 2 Applications and Layered Architectures Sockets.
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: HsinYu Ha.
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
Socket Programming. Computer Science, FSU2 Interprocess Communication Within a single system – Pipes, FIFOs – Message Queues – Semaphores, Shared Memory.
UNIX Sockets Outline UNIX sockets CS 640.
Lecture 3 TCP and UDP Sockets CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
1 Socket Interface. 2 Client-Server Architecture The client is the one who speaks first Typical client-server situations  Client and server on the same.
Socket Programming(1/2). Outline  1. Introduction to Network Programming  2. Network Architecture – Client/Server Model  3. TCP Socket Programming.
1 Socket Interface. 2 Basic Sockets API Review Socket Library TCPUDP IP EthernetPPP ARP DHCP, Mail, WWW, TELNET, FTP... Network cardCom Layer 4 / Transport.
Socket Abstraction and Interprocess Communication
Sockets and Beginning Network Programming
UNIX Sockets COS 461 Precept 1.
CS 1652 Jack Lange University of Pittsburgh
Socket Programming in C
Review: TCP Client-Server Interaction
Interprocess Communication
Interacting With Protocol Software
Transport layer API: Socket Programming
UNIX Sockets Outline Homework #1 posted by end of day
UDP Sockets Programming
Socket Abstraction and Interprocess Communication
Berkeley API Socket Programming
Socket Programming in C
Berkeley API Socket Programming
Introduction to Network Programming (v1.2) Speaker: Mingzhe Li
CS4514 (C04) HELP Session 1 Introduction to Network Programming (v1.4)
Socket Abstraction and Interprocess Communication
Introduction to Network Programming (v1.3) Speaker: Frank Posluszny
Socket Abstraction and Interprocess Communication
Interprocess Communication
Socket Abstraction and Interprocess Communication
Socket Abstraction and Interprocess Communication
Socket Abstraction and Interprocess Communication
CS3516 — TCP/IP Socket Programming
Socket Programming(1/2)
Berkeley API Socket Programming
Sockets.
Presentation transcript:

Introduction to Network Programming Speaker: Jae Chung CS4514 HELP Session 1 Introduction to Network Programming Speaker: Jae Chung

CS4514 Requirements We expect that you have taken a programming course similar to CS2005 before coming into this class. Programs will be done in C or C++ We also expect that you have OS (CS3013) programming background. fork() exec() malloc() or new 11/11/2018 WPI

CS4514 Project1 Your programs should compile and work on garden.WPI.EDU. This system is running Digital Unix (Ultrix). If you program is developed in another platform you should test the software on garden before turning in the assignment. Make sure you have the correct #include in your program. 11/11/2018 WPI

Communication Model Client Server Oracle (3) Connect One Service TCP UDP UDP (2) list (1) register Oracle DNS 11/11/2018 WPI

UDP Transmission (Client) Stevens (Page 212) Connectionless Specify transport address every time you send/recv data Unreliable Protocol Data lost, bit errors Stevens (Page 216) Simple UDP echo client Lenon page78 (robust) socket() sendto() recvfrom() close() 11/11/2018 WPI

Example: UDP Client struct hostent *hp; /* /usr/include/netdb.h */ struct sockaddr_in server; /* /usr/include/netinet/in.h */ int sd, lserver = sizeof( server ); /* prepare a socket */ if ( (sd = socket( AF_INET, SOCK_DGRAM, 0 )) < 0 ) { perror( strerror(errno) ); exit(-1); } 11/11/2018 WPI

Example: UDP Client (Continued) /* prepare server address */ bzero( (char*)&server, sizeof(server) ); server.sin_family = AF_INET; server.sin_port = htons( SERVER_PORT ); if ( (hp = gethostbyname(SERVER_NAME)) == NULL) { perror( strerror(errno) ); exit(-1); } bcopy( hp->addr, (char*)&server.sin_addr, hp->length); 11/11/2018 WPI

Example: UDP Client (Continued) /* prepare your message */ … /* send/receive data */ sendto( sd, sBuf, data_size, 0, (struct sockaddr*)&server, lserver ); recvfrom( sd, rBuf, MAXLEN, 0, (struct sockaddr*)&server, &lserver ); /* close socket */ close( sd ); 11/11/2018 WPI

TCP Connection (Client) Stevens (Page 86) Connection Oriented Specify transport address once at connection Use File Operations read() / write() Reliable Protocol socket() connect() read() / write() send() / recv() close() 11/11/2018 WPI

Example: TCP Client int sd; struct hostent *hp; /* /usr/include/netdb.h */ struct sockaddr_in server; /* /usr/include/netinet/in.h */ /* prepare a socket */ if ( (sd = socket( AF_INET, SOCK_STREAM, 0 )) < 0 ) { perror( strerror(errno) ); exit(-1); } 11/11/2018 WPI

Example: TCP Client (Continued) /* prepare server address */ bzero( (char*)&server, sizeof(server) ); server.sin_family = AF_INET; server.sin_port = htons( SERVER_PORT ); if ( (hp = gethostbyname(SERVER_NAME)) == NULL) { perror( strerror(errno) ); exit(-1); } bcopy( hp->addr, (char*)&server.sin_addr, hp->length); 11/11/2018 WPI

Example: TCP Client (Continued) /* connect to the server */ if (connect( sd, (struct sockaddr*) &server, sizeof(server) ) < 0 ) { perror( strerror(errno) ); exit(-1); } /* send/receive data */ while (1) { read/write(); /* close socket */ close( sd ); 11/11/2018 WPI

TCP Connection (Server) socket() Stevens (Page 86) Bind transport address to socket Listen to the socket Accept connection on a new socket bind() listen() accept() read()/write() close() 11/11/2018 WPI

Example: TCP Server int sd, nsd; struct sockaddr_in server; /* /usr/include/netinet/in.h */ sd = socket( AF_INET, SOCK_STREAM, 0 ); bzero( (char*)&server, sizeof(server) ); server.sin_family = AF_INET; server.sin_port = htons( YOUR_SERVER_PORT ); server.sin_addr.s_addr = htonl( INADDR_ANY ); 11/11/2018 WPI

Example: TCP Server (Continued) bind( sd, (struct sockaddr*) &server, sizeof(server) ); listen( sd, backlog ); while (1) { nsd = accept( sd, (struct sockaddr *) &client, sizeof(client) ); read()/write(); close( nsd ); } close( sd ); 11/11/2018 WPI

Some Useful System Calls Gethostbyname: map hostname to IP addr struct hostent *gethostbyname( char *name ) Getservbyname: look up service name given struct servent *getservbyname( const char *servname, const char *protocol ) Gethostname: get own hostname int gethostname( char *name, size_t len ) Getsockname: map sd to socket addr int getsockname( int sd, struct sockaddr *sa, size_t *lsa ) 11/11/2018 WPI

Oracle Commands (om struct) Find a service: serv.ver = verCur; serv.cmd = cmdGet; serv.uid = ?; serv.sbServ = ?; Register a service: serv.cmd = cmdPut; serv.sbDesc = ?; serv.sa = ? Clear a service: serv.ver = verCur; serv.cmd = cmdClr; serv.uid = ?; serv.sbServ = ?; struct om serv 11/11/2018 WPI

Oracle Communication Example int sd; struct om sendMsg, recvMsg; size_t lom = sizeof(struct om); sendMsg.ver = verCur; sendMsg.cmd = cmdGet; sendto( sd, (void *)&sendMsg, lom, 0, &sa, lsa ); recvfrom( sd, (void *)&recvMsg, lom, 0, &sa, &lsa ); 11/11/2018 WPI

Turnin Your Files Turnin Command Files should include /cs/bin/turnin submit cs4514 proj1 [all files] Files should include All source code (including a Makefile) A documentation file (include your compile command if you don’t offer a Makefile) A result script showing the running result Any custom include files that you used, including oracle.h if you have not used #include “/cs/cs4514/pub/lib/oracle.h” 11/11/2018 WPI

UNIX Programming Some functions that you may need: bind listen accept select sendto/send recvfrom/recv gethostbyname getservbyname gethostname getsockname fork strlen, strtok 11/11/2018 WPI

UNIX Programming (Continued) Use man pages for help on a particular command or function Some man pages are not available on garden.WPI.EDU but available on CCC machines. > man sendto > man 3 printf 11/11/2018 WPI

UNIX Debugging Compile program with –g flag gdb program {core} g++ -g –o program program.cc gcc –g –o program program.c gdb program {core} set args (command arguments) run, where, list, step, break continue inspect, help, quit Can examine specific data in program 11/11/2018 WPI

UNIX Debugging (Continued) Many more options use help to learn more This will be useful to find out where a program crashes or seg faults Can set breakpoints to stop at specific line or function Can set specific data values in program 11/11/2018 WPI

HELP Bring printouts to office hours. Email to TA mailing list with questions. You CAN email a specific TA or SA, but do not expect immediate results, better to use the TA mailing list. We do have a class mailing list that could be used as a last resort. 11/11/2018 WPI