Sockets.

Slides:



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

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.
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.
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.
UDP: User Datagram Protocol. UDP: User Datagram Protocol [RFC 768] r “bare bones”, “best effort” transport protocol r connectionless: m no handshaking.
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.
Computer Networks Sockets. Outline F Socket basics F Socket details.
Operating Systems Sockets. Outline F Socket basics F TCP sockets F Socket details F Socket options F Final notes F Project 3.
CS 360 – Spring 2007 Pacific University TCP section 6.5 (Read this section!) 27 Feb 2007.
1 Tutorial on Socket Programming Computer Networks - CSC 458 Department of Computer Science Yukun Zhu (Slides are mainly from Monia Ghobadi, and Amin Tootoonchian,
Basic Socket Programming TCP/IP overview. TCP interface Reference: –UNIX Network Programming, by Richard Stevens. –UNIX man page.
CPSC 441 TUTORIAL – JANUARY 18, 2012 TA: MARYAM ELAHI INTRODUCTION TO SOCKET PROGRAMMING WITH C.
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.
1 Networking (Stack and Sockets API). 2 Topic Overview Introduction –Protocol Models –Linux Kernel Support TCP/IP Sockets –Usage –Attributes –Example.
Operating Systems Chapter 9 Distributed Communication.
Client-Side Network Programming
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.
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.
Remote Shell CS230 Project #4 Assigned : Due date :
Networking Tutorial Special Interest Group for Software Engineering Luke Rajlich.
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
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.
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.
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.
回到第一頁 Client/sever model n Client asks (request) – server provides (response) n Typically: single server - multiple clients n The server does not need.
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 15 Socket Programming CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
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.
1 Socket Interface. 2 Basic Sockets API Review Socket Library TCPUDP IP EthernetPPP ARP DHCP, Mail, WWW, TELNET, FTP... Network cardCom Layer 4 / Transport.
CSE 333 – SECTION 8 Client-Side Network Programming.
Sockets API Developing Applications using the Sockets API.
Operating Systems Sockets ENCE 360.
Socket Programming in C
Network Programming with Sockets
Tutorial on Socket Programming
Transport layer API: Socket Programming
תקשורת ומחשוב תרגול 3-5 סוקטים ב-C.
UNIX Sockets Outline Homework #1 posted by end of day
Introduction to Socket Programming
Socket Programming in C
Socket Programming.
Socket 程式設計.
ECS152b Behrooz Khorashadi
TCP/IP Socket Programming in C
Sockets Programming Socket to me!.
Sockets Programming Socket to me!.
Internet Networking recitation #8
Outline Communications in Distributed Systems Socket Programming
Today’s topic: Basic TCP API
Presentation transcript:

Sockets

Sockets API Open APIs for communication Assumes any transport Much broader than Java sockets

Sockets API C APIs, but need to vary data structures Provide ‘base’ structures that are place holders for ‘sub’ structures holding data Example – sockaddr, sockaddr_in, sockaddr_un, etc. struct sockaddr { sa_family_t sa_family; /* address family */ char sa_data[14]; }; struct sockaddr_in { sa_family_t sin_family; /* Address family */ in_port_t sin_port; /* Port number */ struct in_addr sin_addr; /* Internet address */ /* Pad to size of `struct sockaddr'. */ unsigned char __pad[__SOCK_SIZE__ - sizeof(short int) - sizeof(unsigned short int) - sizeof(struct in_addr)];

Using Sockets Client Server socket() creates the socket connect() connects socket to specified location (file, port, etc.) send()/recv() communicate with bytes close() close the socket connection Server bind() bind the socket to a name (file, port, etc.) listen() wait for requests

Socket Functions socket(int domain, int type, int protocol) Domains, types, and protocols defined in sys/socket.h Domain specifies the protocol family which will be used AF_UNIX local to host (e.g. pipe) AF_INET inter-network – UDP/TCP Others that are not so relevant today Type specifies the semantics of the communication SOCK_STREAM, SOCK_DGRAM, SOCK_RAW Protocol specifies the particular protocol used with the socket IPPROTO_TCP (if AF_INET) Returns socket index or –1 on error Errors - out of table space, permissions, out of buffer space http://www.hmug.org/man/2/socket.php

Socket Functions send(int socketIndex, const void *msg, size_t len, int flags) recv(int socketIndex, const void *buff, size_t len, int flags) Send/receive bytes between socket sendto() and sendmsg() also send to non-connect()ed sockets close(int socketIndex)

Socket Functions (client) connect(int socketIndex struct sockaddr *addr, socklen_t *addrlen) Initiates a connection to a socket addr identical to bind() and varies based on Blocks if no pending connections in the queue struct sockaddr_in server; memset(&server, 0, sizeof(echoserver)); /* Clear struct */ server.sin_family = AF_INET; /* Internet/IP */ server.sin_addr.s_addr = inet_addr(argv[1]); /* IP address */ server.sin_port = htons(atoi(argv[3])); /* server port */ /* Establish connection */ connect(sock, (struct sockaddr *) &server, sizeof(server))

Socket Functions (server) bind (int socketindex, const struct *sockaddr *name, socklen_t namelen) Assigns a name to an unnamed socket For Unix sockets (on file system), file must be deleted with unlink() Socket index returned by call to socket() Sockaddr types vary based on domains Sockadd_in has port/address, sockaddr_un for file path http://www.hmug.org/man/2/bind.php listen (int socketindex, in backlog) Errors – invalid desctriptor index, wrong type of socket for listen http://www.hmug.org/man/2/listen.php

Socket Functions (server) int socket = accept(int socketIndex struct sockaddr *addr, socklen_t *addrlen) Socket index must be created (socket()), bind()ed, and listen()ing Takes first connection, and allocates new descriptor Blocks if no pending connections in the queue addr contains address of connecting entity, format determined by socket domain