Socket Programming Neil Tang 09/08/2008

Slides:



Advertisements
Similar presentations
Elementary TCP Sockets© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer.
Advertisements

Sockets. Socket Berkeley Software Distribution Handle-like data structure for communicating A socket is an endpoint  Send and receive  Attach a protocol.
Socket Programming Application Programming Interface.
Elementary TCP Sockets Computer Networks Computer Networks Term B10 UNIX Network Programming Vol. 1, Second Ed. Stevens Chapter 4.
1 Socket Interfaces Professor Jinhua Guo CIS527 Fall 2003.
Tutorial 8 Socket Programming
CS 311 – Lecture 18 Outline IPC via Sockets – Server side socket() bind() accept() listen() – Client side connect() Lecture 181CS Operating Systems.
Socket Addresses. Domains Internet domains –familiar with these Unix domains –for processes communicating on the same hosts –not sure of widespread use.
CSE/EE 461 Getting Started with Networking. Basic Concepts  A PROCESS is an executing program somewhere.  Eg, “./a.out”  A MESSAGE contains information.
UNIX Sockets COS 461 Precept 1.
Cs423-cotter1 Example Client Program Reference Comer & Stevens, Chapter 7.
Computer Networks Chapter 1: Foundation
Socket programming in C. Socket programming Socket API introduced in BSD4.1 UNIX, 1981 explicitly created, used, released by apps client/server paradigm.
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.
Fall 2000Datacom 11 Socket Programming Review Examples: Client and Server-Diagnostics UDP versus TCP Echo.
Fall 2000Datacom 11 Lecture 4 Socket Interface Programming: Service Interface between Applications and TCP.
CS345 Operating Systems Φροντιστήριο Άσκησης 2. Inter-process communication Exchange data among processes Methods –Signal –Pipe –Sockets.
CompSci 356: Introduction to Computer Networks Lecture 3: Hardware and physical links Chap 1.4, 2 of [PD] Xiaowei Yang
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.
1 Chapter 1 Foundation Computer Networks: A Systems Approach, 5e Larry L. Peterson and Bruce S. Davie Copyright © 2010, Elsevier Inc. All rights Reserved.
Remote Shell CS230 Project #4 Assigned : Due date :
Page 1 Jan 5, 1998 CMPN 369 CPSC441 Sockets Module Sockets Application Programming Interface (API)
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.
The Sockets Library and Concepts Rudra Dutta CSC Spring 2007, Section 001.
Cli/Serv.: sockets 3/91 Client/Server Distributed Systems v Objectives –describe iterative clients and servers using the UDP protocol ,
UNIX Sockets COS 461 Precept 1. Socket and Process Communication The interface that the OS provides to its networking subsystem application layer transport.
CSE/EE 461 Getting Started with Networking. 2 Basic Concepts A PROCESS is an executing program somewhere. –Eg, “./a.out” A MESSAGE contains information.
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.
Client/Server Socket Programming Project
CS 6401 Introduction to Computer Networks 09/21/2010 Outline - UNIX sockets - A simple client-server program - Project 1 - LAN bridges and learning.
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,
Network Programming By J. H. Wang Nov. 21, Outline Introduction to network programming Socket programming –BSD Socket –WinSock –Java Socket Exercises.
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.
Read() recv() connection establishment Server (connection-oriented protocol) blocks until connection from client Client socket() bind() listen() accept()
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.
Socket programming in C. Socket programming with TCP Client must contact server server process must first be running server must have created socket (door)
Lecture 3 TCP and UDP Sockets CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
Socket Programming in C CS587x Lecture 3 Department of Computer Science Iowa State University.
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.
1 Vehicle Networking Networks Instruction 1 – Echo client/server in C Jeroen Voeten ES, 2012.
Sockets API Developing Applications using the Sockets API.
Sockets and Beginning Network Programming
Sockets and Beginning Network Programming
UNIX Sockets COS 461 Precept 1.
CS 1652 Jack Lange University of Pittsburgh
Socket Programming in C
UNIX Sockets Outline Homework #1 posted by end of day
The University of Adelaide, School of Computer Science
The University of Adelaide, School of Computer Science
Internet and Intranet Protocols and Applications
Berkeley API Socket Programming
The University of Adelaide, School of Computer Science
Socket Programming in C
Berkeley API Socket Programming
Socket Programming(1/2)
Chapter 04. TCP Server/Client.
Internet Networking recitation #8
Berkeley API Socket Programming
The University of Adelaide, School of Computer Science
The University of Adelaide, School of Computer Science
Presentation transcript:

Socket Programming Neil Tang 09/08/2008 CS440 Computer Networks

Outline Network API (Socket) Client/Server Architecture Basic Operations A Simple Example CS440 Computer Networks

Network Software Substantial Increase on Internet Users and Traffic Major Reason for Such Increase: Attractive applications. Major Reasons for Fast Emergence of Applications: A good network architecture and a unified interface. CS440 Computer Networks

Network API (Sockets) Network API (Sockets) The Implementation of API CS440 Computer Networks

Basic Operations Send messages through the socket Receive messages through the socket Create a socket Close the socket Attach the socket to the network CS440 Computer Networks

Client-Server Architecture TCP Connection Client Client CS440 Computer Networks

Basic Operations Create a socket: int socket( int domain, int type, int protocol) domain: PF_INET, PF_UNIX type: SOCK_STREAM, SOCK_DGRAM protocol: 0 (default), IPPROTO_TCP, IPPROTO_UDP, Return: a handle that refers to the socket and can be used on subsequent API calls. CS440 Computer Networks

Basic Operations Client side operations: Open the socket and connects it to the specified server address: int connect( int socket, struct sockaddr* address, int addr_len) Send data over the given socket: int send (int socket, char * msg, int msg_len, int flags) Receive data from the given socket int recv( int socket, char * buffer, int buf_len, int flags) CS440 Computer Networks

Basic Operations Server side operations: Bind the newly created socket to the specified address: int bind( int socket, struct sockaddr* address, int addr_len) Indicate that the server is ready to accept connections on the socket: int listen( int socket, int backlog) backlog: Indicates the maximum number of connections. Accept a connection request from a client: int accept( int socket, struct sockaddr* address, int* addr_len) Return: A new socket. CS440 Computer Networks

A Simple Example: Client /* translate host name into peer's IP address */ hp = gethostbyname(host); if (!hp) { fprintf(stderr, "simplex-talk: unknown host: %s\n", host); exit(1); } /* build address data structure */ bzero((char *)&sin, sizeof(sin)); sin.sin_family = AF_INET; bcopy(hp->h_addr, (char *)&sin.sin_addr, hp->h_length); sin.sin_port = htons(SERVER_PORT); /* active open */ if ((s = socket(PF_INET, SOCK_STREAM, 0)) < 0) { perror("simplex-talk: socket"); CS440 Computer Networks

A Simple Example: Client (Cont’d) if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) { perror("simplex-talk: connect"); close(s); exit(1); } /* main loop: get and send lines of text */ while (fgets(buf, sizeof(buf), stdin)) { buf[MAX_LINE-1] = '\0'; len = strlen(buf) + 1; send(s, buf, len, 0); CS440 Computer Networks

A Simple Example: Server /* build address data structure */ bzero((char *)&sin, sizeof(sin)); sin.sin_family = AF_INET; sin.sin_addr.s_addr = INADDR_ANY; sin.sin_port = htons(SERVER_PORT); /* setup passive open */ if ((s = socket(PF_INET, SOCK_STREAM, 0)) < 0) { perror("simplex-talk: socket"); exit(1); } if ((bind(s, (struct sockaddr *)&sin, sizeof(sin))) < 0) { perror("simplex-talk: bind"); CS440 Computer Networks

A Simple Example: Server (Cont’d) listen(s, MAX_PENDING); /* wait for connection, then receive and print text */ while(1) { if ((new_s = accept(s, (struct sockaddr *)&sin, &len)) < 0){ perror("simplex-talk: accept"); exit(1); } while (len = recv(new_s, buf, sizeof(buf), 0)) fputs(buf, stdout); close(new_s); CS440 Computer Networks

Review Network API (Socket) Client/Server Architecture Basic Operations: socket, connect, send, recv, bind, listen, accept. A Simple Example CS440 Computer Networks