SOCKETS. COMP750 Distributed Systems

Similar documents
Introduction to Socket Programming

The Application Layer: Sockets Wrap-Up

Hyo-bong Son Computer Systems Laboratory Sungkyunkwan University

Socket Programming. CSIS0234A Computer and Communication Networks. Socket Programming in C

Context. Distributed Systems: Sockets Programming. Alberto Bosio, Associate Professor UM Microelectronic Departement

Sockets. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Socket Programming. Dr. -Ing. Abdalkarim Awad. Informatik 7 Rechnernetze und Kommunikationssysteme

WinSock. What Is Sockets What Is Windows Sockets What Are Its Benefits Architecture of Windows Sockets Network Application Mechanics

A Client-Server Exchange

Client Server Computing

Application Architecture

Types (Protocols) Associated functions Styles We will look at using sockets in C Java sockets are conceptually quite similar

Socket Programming. Sungkyunkwan University. Hyunseung Choo Copyright Networking Laboratory

Sockets. Dong-kun Shin Embedded Software Laboratory Sungkyunkwan University Embedded Software Lab.

Oral. Total. Dated Sign (2) (5) (3) (2)

Tutorial on Socket Programming

Processes communicating. Network Communication. Sockets. Addressing processes 4/15/2013

PA #2 Reviews. set_name, get_name, del_name. Questions? Will be modified after PA #4 ~

Distributed Systems Recitation 2. Tamim Jabban

Application Programming Interfaces

A. Basic Function Calls for Network Communications

Introduction to Socket Programming

How do we Communicate? Introduction to Unix Network Programming. What does Alice do? What does Bob do? Two simplest networking programs

CS118 Discussion 1B, Week 1. Taqi Raza BUNCHE 1209B, Fridays 12:00pm to 1:50pm

ECE 435 Network Engineering Lecture 2

Programming with TCP/IP. Ram Dantu

Chapter 6. The Transport Layer. Transport Layer 3-1

SOCKET PROGRAMMING. What is a socket? Using sockets Types (Protocols) Associated functions Styles

Hybrid of client-server and P2P. Pure P2P Architecture. App-layer Protocols. Communicating Processes. Transport Service Requirements

Ports under 1024 are often considered special, and usually require special OS privileges to use.

Socket Programming TCP UDP

Department of Computer Science

Distributed Systems Recitation 2. Tamim Jabban

Unix Network Programming

Session NM056. Programming TCP/IP with Sockets. Geoff Bryant Process software

Lecture 7. Followup. Review. Communication Interface. Socket Communication. Client-Server Model. Socket Programming January 28, 2005

Lab 0. Yvan Petillot. Networks - Lab 0 1

NETWORK PROGRAMMING. Instructor: Junaid Tariq, Lecturer, Department of Computer Science

Network Communication

Socket 101 Excerpt from Network Programming

Socket Programming for TCP and UDP

Computer Network Lab, SS Fachgebiet Technische Informatik, Joachim Zumbrägel. Overview. Sockets. Sockets in C.

Christian Tschudin (basierend auf einem Foliensatz von C. Jelger und T. Meyer) Departement Mathematik und Informatik, Universität Basel

CS321: Computer Networks Introduction to Application Layer

ECE 435 Network Engineering Lecture 2

UNIX Sockets. Developed for the Azera Group By: Joseph D. Fournier B.Sc.E.E., M.Sc.E.E.

sottotitolo Socket Programming Milano, XX mese 20XX A.A. 2016/17 Federico Reghenzani

CS321: Computer Networks Socket Programming

TCP: Three-way handshake

Network Socket Programming - 2 BUPT/QMUL

EECS122 Communications Networks Socket Programming. Jörn Altmann

Chapter 9: UDP sockets & address conversion function

CSC209H Lecture 9. Dan Zingaro. March 11, 2015

The Socket Interface. Socket and Socket Library

The Application Layer: Sockets Wrap-Up

CS 3516: Computer Networks

Outline. Distributed Computing Systems. Socket Basics (1 of 2) Socket Basics (2 of 2) 3/28/2014

Introduction to Network Programming using C/C++

The BSD UNIX Socket Interface (CS 640 Lecture) Assignment 1. Interprocess Communication (IPC) Work Individually (no groups)

What s an API? Do we need standardization?

Elementary TCP Sockets

Client-server model The course that gives CMU its Zip! Network programming Nov 27, Using ports to identify services.

CLIENT-SIDE PROGRAMMING

Networked Applications: Sockets. End System: Computer on the Net

Socket Programming(2/2)

Network Socket Programming - 3 BUPT/QMUL

Network Software Implementations

Network Programming Worksheet 2. Simple TCP Clients and Servers on *nix with C.

Internet applications

System Programming. Sockets

JAVA - NETWORKING (SOCKET PROGRAMMING)

Writing Network Applications using the TCP/IP Protocol Stack: Socket Programming

Reliability is an issue. You cannot afford to have any of the data lost or re-ordered.

Network Socket Programming - 3 BUPT/QMUL

Group-A Assignment No. 6

Outline. Distributed Computer Systems. Socket Basics An end-point for a IP network connection. Ports. Sockets and the OS. Transport Layer.

EECS 123: Introduction to Real-Time Distributed Programming

STUDY OF SOCKET PROGRAMMING

Sockets 15H2. Inshik Song

Lecture 24. Thursday, November 19 CS 375 UNIX System Programming - Lecture 24 1

CSCE 463/612 Networks and Distributed Processing Spring 2017

The Berkeley Sockets API. Networked Systems Architecture 3 Lecture 4

UNIX Network Programming. Overview of Socket API Network Programming Basics

IPv6 Porting Applications

CSCD 330 Network Programming Spring 2018

ICT 6544 Distributed Systems Lecture 5

Chapter 2 Applications and

Interprocess Communication

Network Programming November 3, 2008

Outline. Operating Systems. Socket Basics An end-point for a IP network connection. Ports. Network Communication. Sockets and the OS

Announcements. CS 5565 Network Architecture and Protocols. Queuing. Demultiplexing. Demultiplexing Issues (1) Demultiplexing Issues (2)

Network programming(i) Lenuta Alboaie

UNIX Sockets. COS 461 Precept 1

CS 640: Computer Networking

Network Programming in C: The Berkeley Sockets API. Networked Systems 3 Laboratory Sessions

Networking and Security

UDP CONNECT TO A SERVER

CSc 450/550 Computer Networks Network Architectures & Client-Server Model

CS 43: Computer Networks. 05: Socket Programming September 12-14, 2018

ELEC / COMP 177 Fall Some slides from Kurose and Ross, Computer Networking, 5 th Edition

Transcription:

SOCKETS COMP750 Distributed Systems

Sockets The Socket library is a traditional Application Program Interface (API) to the transport layer. Sockets were originally implemented in Unix systems and have been ported to almost every system. Sockets are a low level interface to the network.

Socket Functions gethostbyname - get the IP address for an IP name gethostname - get the name of the local machine socket - create a new socket connect - make connection to remote host send - transmit data through active connection recv - receive data through active connection close - terminate use of a socket bind - attach a network address to a socket listen - wait for incoming messages accept - begin using incoming connection

Sequence of Socket Procedure Calls

gethostbyname hostent = gethostbyname( IP name ) returns a pointer to a hostent structure. provides the IP address for an IP name.

gethostname gethostname( hostname, buffersize ) puts the IP name of the local computer in the hostname string.

socket descriptor = socket(protofamily,type,protocol) Returns socket descriptor used in subsequent calls protofamily selects protocol family; (e.g. PF_INET - Internet protocols, PF_APPLETALK - AppleTalk protocols) type selects type of communication,sock_dgram - connectionless, SOCK_STREAM - connection-oriented protocol specifies protocol within protocol family: IPPROTO_TCP -selects TCP, IPPROTO_UDP - selects UDP

connect connect(socket,saddress,saddresslen) Client uses connect to establish connection to server Blocks until connection completed (accepted) socket holds descriptor of socket to use saddress is a struct sockaddr that identifies server saddresslen gives length of saddress Usually used with connection-oriented transport protocol Can be used with connectionless protocol Marks local socket with server address Implicitly identifies server for subsequent messages

send send(socket, data, length, flags) Used to send data through a connected socket socket identifies socket data points to data to be sent length gives length of data (in bytes) flags indicate special options

sendto sendto(socket, data, length, flags, destaddr, addrlen) Used for unconnected sockets by explicitly specifying destination sendto adds additional parameters: destaddr - struct sockaddr destination address addrlen - length of destaddr

recv recv(socket, buffer, length,flags) Used to receive incoming data through connected socket socket identifies the socket Data copied into buffer At most length bytes will be recved flags give special options Returns number of bytes actually recved o0implies connection closed o-1implies error

recvfrom recvfrom(socket, buffer, length, flags, sndraddr, addrlen) Like recvfrom (in reverse!) Address of source copied into sndraddr Length of address in addrlen

close close(descriptor) Terminates use of socket descriptor descriptor contains descriptor of socket to be closed

bind bind(socket, localaddr, address) Initially, socket has no addresses attached bind selects either local, remote or both addresses server binds local port number for incoming messages client binds remote address and port number to contact server

listen listen(socket, queuesize) Server uses listen to wait for incoming connections socket identifies socket through which connections will arrive (address) New connection requests may arrive while server processes previous request Operating system can hold requests on queue queuesize sets upper limit on outstanding requests

accept accept(socket, caddress, caddrlen) Server uses accept to accept the next connection request accept call blocks until connection request arrives Returns new socket with server's end of new connection Old socket remains unchanged and continues to field incoming requests caddress returns struct sockaddr client address; format depends on address family of socket caddrlen returns length of address

Socket Address Format struct sockaddr_in { u_char sin_len; /* total length of address */ u_char sin_family; /* family of the address */ u_short sin_port; /* protocol port number */ struct in_addr sin_addr; /* IP address */ char sin_zero[8] /* unused */ } Host entry structure returned by gethostbyname struct hostent { char *h_name; /* official name of host */ char **h_aliases; /* alias list */ int h_addrtype; /* host address type */ int h_length; /* length of address */ char **h_addr_list; /* list of addresses from name server */ }; #define h_addr h_addr_list[0] /* address, for backward compatibility */

Format Conversion int = htons( short ) Host TO Network Short Converts a short int to network standard format. Swaps bytes if necessary. int = ntohs( short) Network TO Host Short Converts a 16 bit integer in network standard format to a short in the local host format. Swaps bytes if necessary.

Microsoft Extensions WSAStartup( version, &wsadata); Must be called before any other socket function. WSADATA is an structure that will receive information about the socket implementation on this system, such as the implementation version. WSACleanup(); Closes all sockets. WSAStartup must be called to use any socket function again.

Java Sockets There are two socket classes in Java java.net.socket for clients java.net.serversocket for servers Sockets create streams that can be used exactly like file streams. Reading and writing to a socket is identical to reading and writing to a file.

Socket Constructor public Socket(String host, int port) throws UnknownHostException, IOException Creates a stream socket and connects it to the specified port number on the named host. Other constructors are available.

Methods public InputStream getinputstream() throws IOException Returns an input stream for this socket. public OutputStream getoutputstream() throws IOException Returns an output stream for this socket.

java.net.serversocket Creates a TCP socket for use by a server program. A server socket waits for requests to come in over the network.

constructor public ServerSocket(int port) throws IOException Creates a server socket on a specified port. A port of 0 creates a socket on any free port.

ServerSocket Methods public Socket accept() throws IOException Listens for a connection to be made to this socket and accepts it. The method blocks until a connection is made. A new Socket is created.

Java Security Java applets running in a browser can only connect to the server that hosts the applet. Java applications generally have no restrictions. Experience shows that network programming is easiest on a PC with Java.