CS4514 (C04) HELP Session 1 Introduction to Network Programming (v1.4)

Slides:



Advertisements
Similar presentations
CS3516 (B10) HELP Session 2 Presented by Lei Cao.
Advertisements

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.
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.
1 Socket Interfaces Professor Jinhua Guo CIS527 Fall 2003.
תקשורת באינטרנט Tutorial 8. 2 n Socket programming u What is socket ? u Sockets architecture u Types of Sockets u The Socket system calls u Data Transfer.
Tutorial 8 Socket Programming
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.
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,
CPSC 441 TUTORIAL – JANUARY 18, 2012 TA: MARYAM ELAHI INTRODUCTION TO SOCKET PROGRAMMING WITH C.
ECE 4110 – Internetwork Programming Client-Server Model.
TCP/IP Protocol Stack IP Device Drivers TCPUDP Application Sockets (Gate to network) TCP: –Establish connection –Maintain connection during the communication.
Assignment 3 A Client/Server Application: Chatroom.
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.
Remote Shell CS230 Project #4 Assigned : Due date :
Networking Tutorial Special Interest Group for Software Engineering Luke Rajlich.
1 Computer Networks An Introduction to Computer Networks University of Tehran Dept. of EE and Computer Engineering By: Dr. Nasser Yazdani Lecture 3: Sockets.
TELE202 Lecture 15 Socket programming 1 Lecturer Dr Z. Huang Overview ¥Last Lecture »TCP/UDP (2) »Source: chapter 17 ¥This Lecture »Socket programming.
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.
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.
2: Application Layer1 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail  SMTP,
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: HsinYu Ha.
Intro to Socket Programming CS 360. Page 2 CS 360, WSU Vancouver Two views: Server vs. Client Servers LISTEN for a connection and respond when one is.
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
CSCI 330 UNIX and Network Programming Unit XIV: User Datagram Protocol.
Socket Programming. Computer Science, FSU2 Interprocess Communication Within a single system – Pipes, FIFOs – Message Queues – Semaphores, Shared Memory.
Inter-Process Communication 9.1 Unix Sockets You may regard a socket as being a communication endpoint. –For two processes to communicate, both must create.
1 Spring Semester 2008, Dept. of Computer Science, Technion Internet Networking recitation #7 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 PROGRAMMING Presented By : Divya Sharma.
Socket Abstraction and Interprocess Communication
Assignment 3 A Client/Server Application: Chatroom
Sockets and Beginning Network Programming
CS 1652 Jack Lange University of Pittsburgh
Socket Programming in C
Review: TCP Client-Server Interaction
Imam Ahmad Trinugroho, ST., MMSI
Interprocess Communication
Transport layer API: Socket Programming
Introduction to Network Programming Speaker: Jae Chung
UNIX Sockets Outline Homework #1 posted by end of day
Socket Abstraction and Interprocess Communication
Berkeley API Socket Programming
Socket Programming in C
Socket Programming.
Berkeley API Socket Programming
Introduction to Network Programming (v1.2) Speaker: Mingzhe Li
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
Internet Networking recitation #8
Berkeley API Socket Programming
Sockets.
Presentation transcript:

CS4514 (C04) HELP Session 1 Introduction to Network Programming (v1.4) Speaker: Chunling Ma HL116, Oct 28th of 2004

Outline Project 1 Overview Unix Network Programming Project Turnin Client Server Communication with netoracle Project Turnin How to find help Additional suggestions / tips 1/14/2019 WPI

CS4514 Project1 Your programs should compile and work on ccc.wpi.edu computers, which are running Linux. Netoracle is running on ccc3.wpi.edu only. Programs should be written in C or C++ If your program is developed on another platform or machine, you should test the software on ccc before turning in the assignment. Make sure you have the correct #include in your program. We have registered a couple of services in oracle that can be used to debug your client. 1/14/2019 WPI

Project 1 Communication Model Client Server (3) Connect to the service TCP UDP UDP (2) List services (1) Register the service netoracle DNS 1/14/2019 WPI

Project 1 missions (in handout) Client: Wait on user’s commands. List all services registered on netoracle. Connect to a service using the transport address returned from netoracle. Server: Register the service to netoracle. Wait for connections and provide the service. 1/14/2019 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() 1/14/2019 WPI

Example: UDP Client struct hostent *hp; /* /usr/include/netdb.h */ /* host info: host name, address, …*/ struct sockaddr_in server; /* /usr/include/netinet/in.h */ /* server socket address */ int sd; /* file descriptor of socket */ size_t lserver = sizeof(server); /* prepare a socket: Internet address family, and datagram socket (for udp) */ if ( (sd = socket(AF_INET, SOCK_DGRAM, 0)) < 0 ) { perror(strerror(errno)); exit(-1); } 1/14/2019 WPI

Example: UDP Client (Continued) /* prepare socket address of server */ bzero((char*)&server, sizeof(server)); server.sin_family = AF_INET; /* endian convert: host to network */ server.sin_port = htons(SERVER_PORT); if ((hp = gethostbyname(SERVER_NAME)) == NULL) { perror(strerror(errno)); exit(-1); } /* copy server host address to server.sin_addr */ bcopy(hp->h_addr, (char*)&server.sin_addr, hp->h_length); 1/14/2019 WPI

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

TCP Connection (Client) Stevens (Page 86) Connection Oriented Specify transport address once at connection Use File Operations on socket descriptor read(sd, …) / write(sd, …) Reliable Protocol socket() connect() read() / write() send() / recv() close() 1/14/2019 WPI

Example: TCP Client int sd; /* file descriptor of socket */ struct hostent *hp; /* /usr/include/netdb.h */ /* host info: host name, address, …*/ struct sockaddr_in server; /* /usr/include/netinet/in.h */ /* server socket address */ size_t lserver = sizeof(server); /* prepare a socket: Internet address family, and byte stream socket (for tcp) */ if ((sd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { perror(strerror(errno)); exit(-1); } 1/14/2019 WPI

Example: TCP Client (Continued) /* prepare server socket address (same as udp) */ 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->h_addr, (char*)&server.sin_addr, hp->h_length); 1/14/2019 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(sd, rBuf, buff_size)/write(sd, sBuf, data_size); /* close socket and disconnect from the server*/ close( sd ); 1/14/2019 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() 1/14/2019 WPI

Example: TCP Server int sd, nsd; /* nsd: file descriptor of new socket for accept */ struct sockaddr_in server; /* /usr/include/netinet/in.h */ /* prepare a socket, same as the one for tcp client */ sd = socket(AF_INET, SOCK_STREAM, 0); /* prepare your server socket address */ bzero((char*)&server, sizeof(server)); server.sin_family = AF_INET; /* Can use 0, then kernel assigns one at bind time */ server.sin_port = htons(YOUR_SERVER_PORT); server.sin_addr.s_addr = htonl(INADDR_ANY); 1/14/2019 WPI

Example: TCP Server (Continued) /* bind socket descriptor to server socket address */ bind(sd, (struct sockaddr*) &server, sizeof(server)); /* listen to incoming connections */ listen(sd, num_of_conns); while (1) { /* accept a connection and copy to a new socket descriptor */ nsd = accept(sd, (struct sockaddr *) &client, sizeof(client)); read(nsd, rBuf, buff_size)/write(nsd, sBuf, data_size); close(nsd); } close(sd); 1/14/2019 WPI

Oracle om Structure struct om { /* oracle message */ char ver; /* version number of this structure */ enum cmd cmd; /* command/reply code */ char sbDesc[cchMaxDesc]; /* description of service */ char uid[luid]; /* user id of requester/provider */ char sbServ[cchMaxServ]; /* name of service */ struct sockaddr_in sa; /* socket addr where service is at */ unsigned long ti; /* time of registration */ }; 1/14/2019 WPI

Oracle Command Structure enum cmd { cmdErr, /* An error occurred. See sbDesc for details */ cmdGet, /* Get the address of a service */ cmdAckGet, /* ACK for cmdGet message */ cmdEnd, /* Last response to a cmdGet message */ cmdPut, /* Register a new service */ cmdAckPut, /* ACK for cmdPut message */ cmdClr, /* Unregister a service */ cmdAckClr /* ACK for cmdClr message */ }; 1/14/2019 WPI

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

Oracle Communication Example (list services) int sd; struct sockaddr_in sa; // Can use gethostbyname() and // getservbyname() to get sa of oracle server size_t lsa = sizeof(sa); struct om sendMsg, recvMsg; size_t lom = sizeof(struct om); sendMsg.ver = verCur; sendMsg.cmd = cmdGet; sendto(sd, (void *)&sendMsg, lom, 0, (struct sockaddr *) &sa, lsa); while (1) { recvfrom(sd, (void *)&recvMsg, lom, 0, (struct sockaddr *) &sa, &lsa); } 1/14/2019 WPI

Turnin Your Files Turnin Command Create a directory to hold your files: mkdir proj1 Copy all files in the current directory to your new directory: cp * proj1 Create a single, compressed archive file containing all of the files in your new directory: tar -czf proj1.tgz proj1 Submit the archive file: /cs/bin/turnin submit cs4514 proj1 proj1.tgz 1/14/2019 WPI

Turnin Your Files (Continued) Files should include All source code (including a Makefile) A README file Describes what portion of the project is implemented and what problems your programs have if there is any gives your compile commands if you don’t offer a Makefile Lists commands to run the programs A result script showing the running results Any custom header files that you used, including oracle.h if you have not used #include “/cs/cs4514/pub/lib/oracle.h” 1/14/2019 WPI

HELP Bring printouts to office hours. Email TA’s (cs4514-ta@cs.wpi.edu) with questions. You CAN email a specific TA, 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. 1/14/2019 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) 1/14/2019 WPI

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

Other resources > man sendto Use man pages for help on a particular command or function (Give the section number). > man sendto > man 2 bind //show bind(2) Internet: Beej's Guide to Network Programming http://www.ecst.csuchico.edu/~beej/guide/net/ 1/14/2019 WPI

UNIX Debugging GDB -- GNU Project Debugger Compile program with –g flag 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 1/14/2019 WPI

UNIX Debugging (Continued) There are many more options use “help” to learn more. Also look at “man gdb”. This will be useful to find out where a program crashes or seg faults. You can set breakpoints to stop at specific line or function. You can set specific data values in program. 1/14/2019 WPI