S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.

Slides:



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

CS 4700 / CS 5700 Network Fundamentals
Sockets: Network IPC Internet Socket UNIX Domain Socket.
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.
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.
Sockets Basics Conectionless Protocol. Today IPC Sockets Basic functions Handed code Q & A.
Socket Programming: a Primer Socket to me!. Feb. 23, 2001EE122, UCB2 Why does one need sockets? application network protocol sockets network.
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.
CS 360 – Spring 2007 Pacific University TCP section 6.5 (Read this section!) 27 Feb 2007.
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,
Introduction to Linux Network 劉德懿
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.
1 Programming with TCP/IP Ram Dantu. 2 Client Server Computing r Although the Internet provides a basic communication service, the protocol software cannot.
UNIX Socket Programming CS 6378
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.
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
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.
IT1352-NETWORK PROGRAMMING AND MANAGEMENT
Sockets CIS 370 Lab 10 UMass Dartmouth. Introduction 4 Sockets provide a simple programming interface which is consistent for processes on the same machine.
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.
---- 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.
UNIT8: SOCKETS Topics Introduction to sockets Socket Addresses
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
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.
CS 6401 Introduction to Computer Networks 09/21/2010 Outline - UNIX sockets - A simple client-server program - Project 1 - LAN bridges and learning.
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
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.
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.
1 Spring Semester 2008, Dept. of Computer Science, Technion Internet Networking recitation #7 Socket Programming.
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.
Sockets API Developing Applications using the Sockets API.
CS 3700 Networks and Distributed Systems
UNIX Sockets COS 461 Precept 1.
Socket Programming in C
Tutorial on Socket Programming
Transport layer API: Socket Programming
CS 3700 Networks and Distributed Systems
תקשורת ומחשוב תרגול 3-5 סוקטים ב-C.
UNIX Sockets Outline Homework #1 posted by end of day
Socket Programming in C
Socket 程式設計.
Internet Networking recitation #8
Sockets.
Presentation transcript:

S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha

W HAT IS SOCKET ? An interface between an application process An Application Programming Interface (API) used for InterProcess Communications (IPC) It can also be called as Berkeley Socket or BSD Socket

T YPES OF SOCKET (1) Address domain Unix domain : address format is Unix pathname Internet domain : address format is host and port number Two types of internet Sockets Stream sockets SOCK_STREAM Connection oriented Rely on TCP to provide reliable two-way connected communication Datagram sockets SOCK_DGRAM Rely on UDP Connection is unreliable

T YPES OF SOCKET (2) Stream sockets – connection-oriented (TCP)

T YPES OF SOCKET (3) Datagram sockets- connectionless socket (UDP)

TCP- BASED SOCKETS

P RIMARY S OCKET C ALLS (1) Socket() : Returns a file descriptor(socket ID) if successful, -1 otherwise. Arguments Domain: set to AF_INET Type: SOCK_STREAM SOCK_DGRAM SOCK_SEQPACKET Protocol: If it is set as zero, then socket will choose the correct protocol based on type. int socket(int domain, int type, int protocol);

P RIMARY S OCKET C ALLS (2) Bind() : Associate a socket id with an address to which other processes can connect. Arguments Sockfd: It is the socket id My_addr: a pointer to the address family dependent address structure Addrlen: It is the size of *my_addr int bind(int sockfd, struct sockaddr *my_addr, int addrlen);

P RIMARY S OCKET C ALLS (3) Listen() : Return 0 on success, or –1 if failure Arguments Sockfd: It is socket id created by socket() Backlog : It is used to constraint the number of connection int listen(int sockfd, int backlog);

P RIMARY S OCKET C ALLS (4) Connect() : connect to a remote host Arguments Sockfd: It is the socket descriptor returned by socket() serv_addr : It is a pointer to to struct sockaddr that contains information on destination IP address and port Addrlen: It is set to sizeof(struct sockaddr) int connect(int sockfd, struct sockaddr *serv_addr, int addrlen);

P RIMARY S OCKET C ALLS (5) Accept() : gets the pending connection on the port you are listen()ing on. Arguments Sockfd: It is the same socket id used by listen() Addr: It is a pointer to a local struct sockaddr which stores the information about incoming connection Addrlen: It is set to sizeof(struct sockaddr_in) int accept(int sockfd, struct sockaddr *addr, int *addrlen);

P RIMARY S OCKET C ALLS (6) Send() : Send a message. Returns the number of bytes sent or -1 if failure. Arguments Sockfd: It is the same socket id used by socket() or accept() msg: It is the pointer to the data you want to send Len: data length is sizeof(msg) Flags : It is set to be zero int send(int sockfd, const void *msg, int len, int flags);

P RIMARY S OCKET C ALLS (7) recv() : Receive up to len bytes in buf. Returns the number of bytes received or -1 on failure. Arguments Sockfd: It is the socket descriptor to read from buf: It is the buffer to read the information info Len: It is the maximum length of the buffer Flags : It is set to be zero int recv(int sockfd, void *buf, int len, unsigned int flags);

P RIMARY S OCKET C ALLS (8) shutdown() : disable sending or receiving based on the value how. Arguments Sockfd How Set it to 0 will disable receiving Set it to 1 will disable sending Set it to 2 will disable both sending and receiving int shutdown(int sockfd, int how);

P RIMARY S OCKET C ALLS (9) Close() : Close connection corresponding to the socket descriptor and frees the socket descriptor. int close(int sockfd)

EXAMPLE – SERVER (1)

EXAMPLE – SERVER (2)

EXAMPLE – C LIENT (1)

EXAMPLE – CLIENT (2)

R EFERENCE ftp://ftp.sas.com/techsup/download/SASC/share /S5958v2.pdf Beej's Guide to Network Programming Using Internet Sockets Sockets Tutorial