Sockets

Páginas: 12 (2786 palabras) Publicado: 26 de octubre de 2011
The Socket API

10/26/2011

1

Introduction
• The socket API is an Interprocessing Communication (IPC) programming interface originally provided as part of the Berkeley UNIX operating system. • It has been ported to all modern operating systems, including Sun Solaris and Windows systems. • It is a de facto standard for programming IPC, and is the basis of more sophisticated IPC interfacesuch as remote procedure call (RPC) and remote method invocation (RMI).
10/26/2011 2

The conceptual model of the socket API
Process A Process B

a socket

Logical port numbers: 1,024 -- 65,535 (216 - 1)
10/26/2011 3

The socket API
• A socket API provides a programming construct termed a socket. A process wishing to communicate with another process must create an instance, orinstantiate, such a construct (socket) • The two processes then issue operations provided by the API to send and receive data (e.g., a message)
10/26/2011 4

Datagram Socket vs. Stream Socket
• A socket programming construct can make use of either the UDP (User Datagram Protocol ) or TCP (Transmission Control Protocol ). • A socket is a generalization of the UNIX file access mechanism that providesan endpoint for communication. A datagram consists of a datagram header, containing the source and destination IP addresses, and a datagram data area. • Sockets that use UDP for transport are known as datagram sockets, while sockets that use TCP are termed stream sockets.

• Q: can a process contain both UDP and TCP sockets?
10/26/2011 5

UDP vs. TCP
• reliable, in-order delivery (TCP)
–congestion control – flow control – connection setup

• unreliable, unordered delivery: UDP
– ―best-effort‖ service – loss tolerant; rate sensitive – DNS, streaming multimedia apps
10/26/2011 6

Connection-oriented & connectionless Datagram socket
• Datagram sockets can support both connectionless and connection-oriented communications at the application layer. This is so because eventhough datagrams are sent or received without the notion of connections at the transport layer, the runtime library of the socket API can create and maintain logical connections for datagrams exchanged between two processes • The runtime library of an API is a set of software that is bound to the program during execution in support of the API.
10/26/2011 7

Connection-oriented & connectionlessDatagram socket
socket
API runtime support

Process A

Process B

socket
API runtime
support

transport layer software

transport layer software

connectionless datagram socket a datagram a logical connection created and maintained by the runtime support of the datagram socket API socket
API runtime support

Process A

Process B

socket
API runtime
support

transport layersoftware

transport layer software

connection-oriented datagram socket

10/26/2011

8

The Java Datagram Socket API
• There are two Java classes for the datagram socket API: - the DatagramSocket class for the sockets. - the DatagramPacket class for the datagrams. A process wishing to send or receive data using this API must instantiate a
– – DatagramSocket object--a socketDatagramPacket object--a datagram





Each socket in a receiver process is said to be bound to a UDP port of the machine local to the process.

10/26/2011

9

The Java Datagram Socket API
To send a datagram to another process, a process: • creates a DatagramSocket (socket) object, and an object that represents the datagram itself. This datagram object can be created by instantiating aDatagramPacket object, which carries a reference to a byte array and the destination address--host ID and port number, to which the receiver’s socket is bound. • issues a call to the send method in the DatagramSocket object, specifying a reference to the DatagramPacket object as an argument.
10/26/2011 10

The Java Datagram Socket API
• DatagramSocket mySocket = new DatagramSocket(); // any...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • sockets
  • sockets
  • Sockets
  • Sockets
  • Sockets
  • Sockets
  • Comunicacion entre sOCKETS
  • Sockets de windows

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS