CS 360 – Spring 2007 Pacific University TCP section 6.5 (Read this section!) 27 Feb 2007.

Slides:



Advertisements
Similar presentations
Sockets: Network IPC Internet Socket UNIX Domain Socket.
Advertisements

Elementary TCP Sockets© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer.
Today’s topic: Basic TCP API –Socket –Bind –Listen –Connect –Accept –Read –Write –Close.
Sockets CS 3516 – Computer Networks. Outline Socket basics Socket details (TCP and UDP) Socket options Final notes.
Distributed Computing Systems Sockets. Outline Socket basics Socket details (TCP and UDP) Socket options Final notes.
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.
Multimedia Networking Sockets. Outline Socket basics Socket details (TCP and UDP) Socket options Final notes.
Socket Programming: a Primer Socket to me!. Feb. 23, 2001EE122, UCB2 Why does one need sockets? application network protocol sockets network.
Sockets IMGD Outline Socket basics Socket details (TCP and UDP) Socket options Final notes.
Tutorial 8 Socket Programming
Programming with Berkeley Sockets Presented by Chris GauthierDickey Written by Daniel Stutzbach (I think!) for CIS 432/532 Useful References: ● man pages.
Introduction to Socket Programming April What is a socket? An interface between application and network –The application creates a socket –The socket.
CSE/EE 461 Getting Started with Networking. Basic Concepts  A PROCESS is an executing program somewhere.  Eg, “./a.out”  A MESSAGE contains information.
Introduction to Project 1 Web Client and Server Jan 2006.
Lecture 10 Overview. Network API Application Programming Interface – Services that provide the interface between application and protocol software often.
Operating Systems Sockets. Outline F Socket basics F TCP sockets F Socket details F Socket options F Final notes F Project 3.
UNIX Sockets COS 461 Precept 1. Clients and Servers Client program – Running on end host – Requests service – E.g., Web browser Server program – Running.
1 Tutorial on Socket Programming Computer Networks - CSC 458 Department of Computer Science Yukun Zhu (Slides are mainly from Monia Ghobadi, and Amin Tootoonchian,
UNIX Sockets COS 461 Precept 1.
Sockets CIS 370 Fall 2009, UMassD. Introduction  Sockets provide a simple programming interface which is consistent for processes on the same machine.
Basic Socket Programming TCP/IP overview. TCP interface Reference: –UNIX Network Programming, by Richard Stevens. –UNIX man page.
CS1652 September 13th, 2012 The slides are adapted from the publisher’s material All material copyright J.F Kurose and K.W. Ross, All Rights.
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.
Network Programming Tutorial #9 CPSC 261. A socket is one end of a virtual communication channel Provides network connectivity to any other socket anywhere.
Elementary TCP Sockets
Zhu Reference: Daniel Spangenberger Computer Networks, Fall 2007 PPT-4 Socket Programming.
CS345 Operating Systems Φροντιστήριο Άσκησης 2. Inter-process communication Exchange data among processes Methods –Signal –Pipe –Sockets.
IT1352-NETWORK PROGRAMMING AND MANAGEMENT
---- IT Acumens. COM IT Acumens. COMIT Acumens. COM.
Remote Shell CS230 Project #4 Assigned : Due date :
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.
CSCE 515: Computer Network Programming UDP Socket Wenyuan Xu Department of Computer Science and Engineering.
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.
UNIX Sockets COS 461 Precept 1. Socket and Process Communication The interface that the OS provides to its networking subsystem application layer transport.
Introduction to Socket
Socket Programming Lab 1 1CS Computer Networks.
CSCI 330 UNIX and Network Programming Unit XV: Transmission Control Protocol.
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: HsinYu Ha.
Introduction to Sockets
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()
CSCI 330 UNIX and Network Programming Unit XIV: User Datagram Protocol.
UNIX Sockets Outline UNIX sockets CS 640.
1 Spring Semester 2008, Dept. of Computer Science, Technion Internet Networking recitation #7 Socket Programming.
Carnegie Mellon Proxy & Networking : Introduction to Computer Systems – Recitation H April 11, 2011.
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.
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.
Sockets API Developing Applications using the Sockets API.
CSCE 313 Network Socket MP8 DUE: FRI MAY 5, 2017
CS 3700 Networks and Distributed Systems
CS 1652 Jack Lange University of Pittsburgh
Socket Programming in C
Tutorial on Socket Programming
Transport layer API: Socket Programming
Socket Programming in C
TCP Sockets Programming
Socket 程式設計.
Internet Networking recitation #8
Outline Communications in Distributed Systems Socket Programming
Sockets.
Today’s topic: Basic TCP API
Presentation transcript:

CS 360 – Spring 2007 Pacific University TCP section 6.5 (Read this section!) 27 Feb 2007

CS 360 – Spring 2007 Pacific University TCP Transmission Control Protocol (RFC 793/and many more) Reliable, connection-based protocol –byte stream –max packet size: 64 KB (1460 bytes is often the practical limit) Tanenbaum, Figure 6-28, page 534

CS 360 – Spring 2007 Pacific University Socket Libraries (Unix/Linux) This is all the same, just like UDP! #include // data types #include // socket interface #include // Internet interface The socket is the common Unix interface to the network –a socket represents an end point for network communication –Berkeley Software Distribution socket API 4.2 BSD Unix most OSes now provide a BSD socket interface for networking –Microsoft Windows almost provides it defacto standard –a socket is represented by an int

CS 360 – Spring 2007 Pacific University API Usage: Call Sequences TCP over IP (connection-based): socket() bind() listen() accept() recv()/send() close() server socket() connect() send()/recv() close() client

CS 360 – Spring 2007 Pacific University Socket library functions TCP over IP –domain (protocol family): PF_INET –type: SOCK_STREAM –protocol: IPPROTO_TCP see /etc/protocols for a list –address family: AF_INET int socket(int domain, int type, int protocol) int bind(int sockfd, const struct sockaddr *my_addr, socklen_t addrlen) –actually use struct sockaddr_in for IP networking

CS 360 – Spring 2007 Pacific University Socket library functions int listen(int sockfd, int backlog) –backlog defines the length of the queue of pending connections –If a connection request arrives with the queue full the client may receive an error with an indication of ECONNREFUSED int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen) –addr is the address of the incoming connection –really use a struct sockaddr_in* ssize_t send(int sockfd, const void *buf, size_t len, int flags); –flags sets some options ssize_t recv(int sockfd, void *buf, size_t len, int flags); –flags sets some options: MSG_WAITALL, etc.

CS 360 – Spring 2007 Pacific University Socket library functions int connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen); –again, use struct sockaddr_in for IP connections –this struct is filled with address information specifying the destination of the data int close(int sockfd) –just like closing a file int setsockopt(int sockfd, int level, int ptname, const void *optval,socklen_t optlen) - #include –manipulate the options associated with a socket –level: SOL_TCP for options to TCP –man socket for full list of options –TCP_NODELAY: send data immediately

CS 360 – Spring 2007 Pacific University Code: Client! page 490 has a TCP example –it uses read/write rather than recv/send. why? struct sockaddr_in sAddr; int addrLen = sizeof(struct sockaddr_in); int sock; int connectStatus; char buf[1024]; int bufLen = 1024; sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); memset(&sAddr, 0, addrLen); sAddr.sin_family = AF_INET; sAddr.sin_port = htons(PORT); sAddr.sin_addr.s_addr = inet_addr(“ ”); connectStatus = connect(sock, &sAddr,addrLen); if( send(sock, (void)*buf, bufLen, 0) == -1) { } if( recv(sock, (void)*buf, bufLen, MSG_WAITALL) == -1) { } close(sock);

CS 360 – Spring 2007 Pacific University Code: Server! struct sockaddr_in sAddr; int addrLen = sizeof(struct sockaddr_in); int listenSock, dataSock, status, one = 1; char buf[1024]; int bufLen = 1024; listenSock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); status = setsockopt (listenSocket, SOL_TCP, TCP_NODELAY, &one, sizeof(int)); memset(&sAddr, 0, addrLen); sAddr.sin_family = AF_INET; sAddr.sin_port = htons(PORT); sAddr.sin_addr.s_addr = NULL; status = bind(listenSock, &sAddr, addrLen); status = listen(listenSocket, 10); dataSock = accept(listenSocket, &sAddr, &addrLen); status = recv(dataSock, (void)*buf, bufLen, MSG_WAITALL); status = send(dataSock, (void)*buf, bufLen, 0); close(dataSock); close(listenSock);

CS 360 – Spring 2007 Pacific University Your Project A stream of MathPackets –calculation stream Server needs to be multithreaded –one thread per connection Server stores intermediate value for each stream –perform calculations as the packets arrive A client can set a named value –4 character name (exactly) –integer –accessible by all clients of the server

CS 360 – Spring 2007 Pacific University Suggested Road Map 1)Convert Project #1 to TCP 2)Add the calculation stream 3)Add named values 4)Add threads to the server Plan ahead! –think about threads as you work with the server –build a nice data structure in step three –use mutexes efficiently in step 4 –commit to Subversion often! –I will be checking through your repository name your project PUNetID_cs36007_PA3 –Start Early!