Sockets. Socket Berkeley Software Distribution Handle-like data structure for communicating A socket is an endpoint  Send and receive  Attach a protocol.

Slides:



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

Networking. The Network is the Computer Client-Server computing Peer-to-Peer The Web Today’s networking is wonderful, but  How is it done?
Today’s topic: Basic TCP API –Socket –Bind –Listen –Connect –Accept –Read –Write –Close.
Socket Programming Application Programming Interface.
Distributed Computing Systems Sockets. Outline Socket basics Socket details (TCP and UDP) Socket options Final notes.
Socket programming Tasos Alexandridis 1HY335a - Socket Programming.
Sockets Programming CS144 Review Session 1 April 4, 2008 Ben Nham.
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.
1 Socket Interfaces Professor Jinhua Guo CIS527 Fall 2003.
Tutorial 8 Socket Programming
Introduction to Socket Programming April What is a socket? An interface between application and network –The application creates a socket –The socket.
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.
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,
UNIX Sockets COS 461 Precept 1.
Network Programming Sockets and Winsock. Please Be Responsible We all know that the Internet is full of security holes –most of them do not require any.
Basic Socket Programming TCP/IP overview. TCP interface Reference: –UNIX Network Programming, by Richard Stevens. –UNIX man page.
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.
Operating Systems Chapter 9 Distributed 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.
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.
Sirak Kaewjamnong Computer Network Systems
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.
CS162B: IPv4 Socketing Jacob T. Chan. Socketing in the Real World  Most computer games are multiplayer in nature or have multiplayer components  DotA,
---- 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.
The Sockets Library and Concepts Rudra Dutta CSC Spring 2007, Section 001.
TELE202 Lecture 15 Socket programming 1 Lecturer Dr Z. Huang Overview ¥Last Lecture »TCP/UDP (2) »Source: chapter 17 ¥This Lecture »Socket programming.
An Introductory 4.4BSD Interprocess Communication Tutorial Stuart Sechrest.
CSCE 515: Computer Network Programming UDP Socket Wenyuan Xu Department of Computer Science and Engineering.
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
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.
回到第一頁 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 3 TCP and UDP Sockets CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
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.
Sockets API Developing Applications using the Sockets API.
Jim Fawcett CSE 681 – Software Modeling & Analysis Fall 2002
Socket Programming in C
Transport layer API: Socket Programming
תקשורת ומחשוב תרגול 3-5 סוקטים ב-C.
UNIX Sockets Outline Homework #1 posted by end of day
Socket Programming in C
Socket 程式設計.
ECS152b Behrooz Khorashadi
Socket Programming(1/2)
Socket Programming Neil Tang 09/08/2008
Internet Networking recitation #8
Sockets.
Jim Fawcett CSE 681 – Software Modeling & Analysis Summer 2003
Presentation transcript:

Sockets

Socket Berkeley Software Distribution Handle-like data structure for communicating A socket is an endpoint  Send and receive  Attach a protocol  UDPuser datagram (best effort)  TCPtransmission control (reliable stream)

Sockets – Connection-Oriented

Sockets Sockaddr_in  struct sockaddr_in {short sin_family; u_short sin_port; struct inaddr sin_addr;char sin_zero[8];};

A situation Client can determine IP address of server  But how can it know the socket id?  Socket is a handle  Name server can’t deal with all the handles Bind provides a way to map a socket to a port that exists in the network name space.

Client-Server Client  Create the socket  Get the address of the server  Fill in the sockaddr_in structure  Connect to server Server  Create the socket  Fill in the sockaddr_in structure  Bind to a port  Listen  Accept connections

Sockets Created by OS.  int socket(int af, int type, int protocol)  afAF_INET  typeSOCK_STREAM or SOCK_DGRAM  protocol0 (determined by type)

Client filling in sockaddr_in char *serverHostName = “orion-16”; struct sockaddr_in addr; memset(&addr, 0, sizeof(SOCKADDR_IN)); addr.sin_family = AF_INET addr.sin_port = htons((u_short) port) struct hostent *host; host = gethostbyname(serverHostName); memcpy(&addr.sin_addr, host->h_addr_list[0], host->h_length);

Server filling in sockaddr_in struct sockaddr_in addr; memset(&addr, 0, sizeof(SOCKADDR_IN)); addr.sin_family = AF_INET addr.sin_port = htons((u_short) port) addr.sin_addr.s_addr = INADDR_ANY

Server Map to the network port  int bind(int sock, const struct sockaddr *name, int namelen)  name is pointer to sockaddr_in structure from previous  namelen is size of sockaddr_in Set socket to listen mode  int listen(int sock, int backlog)  backlogmax number of pending connections

Connections Client initiate a connection  int connect(int sock, const struct sockaddr *name, int namelen); Server accepting a connection  SOCKET accept(int sock, struct sockaddr *addr, int *addrlen);  creates a new socket for the communication  Server is free to accept another connection on that socket  best to fire off a thread to handle the connection. send the new socket as an argument to the thread.

Socket Communication Sending data  send(int sock, char *buffer, int bufflen, int flags)  flags is generally 0 Receiving data  recv(int sock, char *buffer, int bufflen, int flags)  Make sure you have enough room  flags is generally 0

Socket Overview sc=socket(..) ss=socket(..) Client Server bind(ss,..) listen(ss,..) foo=accept(ss,..) connect(sc,..) write(sc,buf,len) read(foo,buf,len)

Socket Operations Creating a socket int socket(int domain, int type, int protocol) domain=PF_INET, PF_UNIX type=SOCK_STREAM, SOCK_DGRAM Passive open on server int bind(int socket, struct sockaddr *address, int addr_len) int listen(int socket, int backlog) int accept(int socket, struct sockaddr *address, int *addr_len) Active open on client int connect(int socket, struct sockaddr *address, int addr_len) Sending and receiving messages int write(int socket, char *message, int msg_len, int flags) int read(int socket, char *buffer, int buf_len, int flags)

#include client() { int skt; struct sockaddr_in name; skt = socket(AF_INET, SOCK_STREAM, 0); // Fill in the name data structure sockaddr_in connect(skt, &name, sizeof(name)); // Communicate using send and recv close(skt); }

#include server() { SOCKET listenSkt, newSkt; struct sockaddr_in serverName, clientName; listenSkt = socket(AF_INET, SOCK_STREAM, 0); //Fill in serverName bind(listenSkt, &serverName, sizeof(serverName)); listen(listenSkt, 5); newSkt = accept(listenSkt, &clientName, sizeof(clientName)); // Fire off a thread to do communication using send and recv on newSkt // Loop back and accept another connection close(skt); }