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.

Slides:



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

Sockets: Network IPC Internet Socket UNIX Domain Socket.
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.
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.
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.
CS 360 – Spring 2007 Pacific University TCP section 6.5 (Read this section!) 27 Feb 2007.
Basic Socket Programming TCP/IP overview. TCP interface Reference: –UNIX Network Programming, by Richard Stevens. –UNIX man page.
Elementary UDP Sockets© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer.
TCP Socket Programming. r An abstract interface provided to the application programmer  File descriptor, allows apps to read/write to the network r Allows.
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.
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.
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.
Lab #1: Network Programming using Sockets By J. H. Wang Nov. 28, 2011.
Remote Shell CS230 Project #4 Assigned : Due date :
Lab 5 Sockets. Useful Sockets Links (courtesy of Stanford University) Programming UNIX Sockets in C - Frequently Asked Questions
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.
Cli/Serv.: sockets 3/91 Client/Server Distributed Systems v Objectives –describe iterative clients and servers using the UDP protocol ,
CSCE 515: Computer Network Programming UDP Socket Wenyuan Xu Department of Computer Science and Engineering.
Introduction to Socket
TELE 402 Lecture 6: Name and address conversions 1 Overview Last Lecture –Socket Options and elementary UDP sockets This Lecture –Name and address conversions.
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,
Programming with UDP – II Covered Subjects: Creating UDP sockets Client Server Sending data Receiving data Connected mode.
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: HsinYu Ha.
Review: –Concurrent server and multiplexed server How they work? Which one is better?
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.
Review: – Why layer architecture? – peer entities – Protocol and service interface – Connection-oriented/connectionless service – Reliable/unreliable service.
Read() recv() connection establishment Server (connection-oriented protocol) blocks until connection from client Client socket() bind() listen() accept()
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.
The Socket Interface A Networking Application Program Interface.
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.
Sockets Intro to Network Programming. Before the internet... Early computers were entirely isolated No Internet No network No model No external communications.
1 Socket Interface. 2 Basic Sockets API Review Socket Library TCPUDP IP EthernetPPP ARP DHCP, Mail, WWW, TELNET, FTP... Network cardCom Layer 4 / Transport.
1 UDP Sockets Programming Creating UDP sockets.Creating UDP sockets. –Client –Server Sending data.Sending data. Receiving data.Receiving data. Connected.
Name and Address Conversions
Assignment 3 A Client/Server Application: Chatroom
Chapter 10 IPv4 and IPv6 Interoperability
Socket Programming in C
Review: TCP Client-Server Interaction
Interacting With Protocol Software
Transport layer API: Socket Programming
Introduction to Network Programming Speaker: Jae Chung
UNIX Sockets Outline Homework #1 posted by end of day
UDP Sockets Programming
Berkeley API Socket Programming
Berkeley API Socket Programming
TCP/IP Socket Programming in C
Introduction to Network Programming (v1.2) Speaker: Mingzhe Li
CS4514 (C04) HELP Session 1 Introduction to Network Programming (v1.4)
Introduction to Network Programming (v1.3) Speaker: Frank Posluszny
CS3516 — TCP/IP Socket Programming
Berkeley API Socket Programming
Sockets.
Presentation transcript:

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 be done in C or C++ We also expect that you will have had OS before coming into this class –Fork() –Exec() –Malloc() or new

Programs Programs need to work on garden.wpi.edu This system is Digital Unix If you program on another platform you need to test the software on garden before turning in the assignment. Make sure you have the correct includes in your program

ClientServerOracle (2) register (1) list (3) ConnectOneService DNS TCP UDP

UDP Connection (Client) P. 212 Stevens socket() sendto() recvfrom() close()

Example -- UDP Connection (Client) if ( (sd = socket( AF_INET, SOCK_DGRAM, 0 )) < 0 ) { perror( strerror(errno) ); exit(-1); } bzero( (char*)&client, sizeof(client) ); client.sin-family = AF-INET; client.sin-port = htons(0); client.sin-addr.s-addr = htonl( INADDR-ANY ); NOTE: struct sockaddr_in client, server; struct hostent *hp; For more, see P78-79 of textbook.

Example -- UDP Connection (Client) Cont. sendto ( sd, sBuf, data-size, 0, (struct sockaddr*)&server, sizeof(server) ); … recvfrom ( sd, rBuf, MAXLEN, 0, (struct sockaddr*)&server, sizeof(server) ); … bzero( (char*)&server, sizeof(server) ); server.sin-family = AF_INET; server.sin-port = htons( SERVER-PORT ); // May not always need If ( (hp = gethostbyname(SERVER-NAME)) == NULL) { perror( strerror(errno) ); exit(-1); } bcopy( hp->addr, (char*)&server.sin-addr, hp->length); … close( sd );

TCP Connection (Client) P. 86 Stevens socket( ) read( )/write( ) send( )/recv( ) connect( ) close()

Example: TCP Connection (Client) if ( (sd = socket( AF_INET, SOCK_STREAM, 0 )) < 0 ) { perror( strerror(errno) ); exit(-1); } bzero( (char*)&client, sizeof(client) ); client.sin-family = AF-INET; client.sin-port = htons(0); client.sin-addr.s-addr = htonl( INADDR-ANY ); NOTE: struct sockaddr_in client, server; struct hostent *hp; For more, see P74-75 of textbook.

Example: TCP Connection (Client) Cont. 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); if ( connect( sd, (struct sockaddr*)&server, sizeof(server) ) < 0 ) { perror( strerror(errno) ); exit(-1); } while (1) { … read/write() } close( sd );

Example TCP Connection (Server) P. 86 Stevens socket() bind() listen() accept() sd = socket( AF_INET, SOCK_STREAM, 0 ); bzero( (char*)&server, sizeof(server) ); server.sin-family = AF-INET; server.sin-port = YOUR-SERVER-PORT; server.sin-addr.s-addr = htonl(INADDR-ANY); bind( sd, (struct sockaddr*) &server, sizeof(server) ); listen( sd, backlog ); while (1) { new-sd = accept ( sd, (struct sockaddr *) &client, sizeof(client) ); read()/write(); … } NOTE: struct sockaddr_in server; For more, see P73 of textbook. close( sd ); close()

Send/recv the om struct ssize_t recv(int sockfd, void *buff, size_t nbytes, int flags); ssize_t send(int sockfd, const void *buff, size_t nbytes, int flags); Usage: struct om sendMsg, recvMsg; … set the field’s values in sendMsg first send(s, (void *)&sendMsg, lom, 0); recv(s, (void *)&recvMsg, lom, 0);

om struct (struct om serv, newServ;) To Find a service info. in oracle: serv.ver = verCur; serv.cmd = cmdGet; serv.uid = ?; serv.sbServ = ?; Register a service: newServ.cmd = cmdPut; newServ.uid = ?; newServ.sbServ = ?; newServ.sbDesc = ?; newServ.sa = ? Clear a service: oldServ.ver = verCur; oldServ.cmd = cmdClr; odlServ.uid = ?; oldServ.sbServ = ?;

Some system calls – gethostbyname & getservbyname gethostbyname: mapping from host name to IP address struct hostent *gethostbyname(const char *hostname) Getservbyname: looks up a service given its name struct servent *getservbyname(const char *servname, const char *protoname) hostname = “garden.wpi.edu” servname = “netoracle”

Turnin your files Use /cs/bin/turnin submit cs4514 proj1 [all files] Files should include - source code which can be compiled without errors - a documentation file (include your compile command) - 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”

UNIX Programming Some functions that you may need: –Fork –Bind –Sendto/send –Recvfrom/recv –Gethostbyname –Getservbyname –Strlen –Strtok

UNIX Programming (cont.) –Accept –Listen –Select There are a large number of system calls that you will use in your programs Use man pages for help on a particular command or function

UNIX debugging 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 inspect help quit Can examine specific data in program

UNIX debugging(cont.) 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

HELP Bring printouts to office hours to TA list with questions You CAN a specific TA, but do not expect immediate results, better to use alias. We do have a class mailing list that could be used as a last resort