1 / 15

Introduction of Socket Programming

Introduction of Socket Programming. L.Aseel AlTurki King Saud University. Outline. Client/Server paradigm Addressing Socket addresses Socket programming. Client/Server Paradigm. Client (local) Process. Server (remote)Process. Local Host. Remote Host. Addressing. needs.

fiona
Télécharger la présentation

Introduction of Socket Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction of Socket Programming L.AseelAlTurki King Saud University

  2. Outline • Client/Server paradigm • Addressing • Socket addresses • Socket programming

  3. Client/Server Paradigm Client (local) Process Server (remote)Process Local Host Remote Host

  4. Addressing needs Transport Layer Port number needs Network Layer IP address needs Data Link Layer MAC address

  5. Addressing IANA Ranges: Well-Known ports(0 to 1023) Registered ports(1024 to 49,151) Dynamic ports(49,152 to 65,535)

  6. Socket Addresses • The combination of an IP address and a port number is called a socket address. • A socket is defined as "the endpoint in a connection.“ • Sockets are the fundamental technology for programming software to communicate on TCP/IP networks. A socket provides a bidirectional communication endpoint for sending and receiving data with another socket.

  7. Socket Addresses (cont..) • Sockets are interfaces that can "plug into" each other over a network. Once so "plugged in", the programs so connected communicate (TCP). • Transport layer needs a pair of socket addresses: the client socket address and the server socket address. • The IP header contains IP addresses; the UDP or TCP header contains the port numbers.

  8. Socket Programming • Socket programming is a method for communication between a client program and a server program in a network. • Sockets are created and used with a set of programming requests or "function calls" sometimes called the sockets application programming interface (API). • The communication between the client and server process may either be connection-oriented (such as an established TCP virtual circuit or session), or connectionless (based on UDP datagrams).

  9. Socket Programming (cont..) • Socket connections normally run between two different computers on a LAN or across the Internet, but they can also be used for inter-process communication on a single computer.

  10. Socket Programming (cont..) • Socket connections normally run between two different computers on a LAN or across the Internet, but they can also be used for inter-process communication on a single computer. • A program that can act both as a client and a server is based on peer-to-peer communication. • an examples for the uses of socket programming: Web browsers.

  11. process process Transport layer protocol Transport layer protocol socket socket Socket Programming (cont..) controlled by application developer controlled by application developer controlled by operating system controlled by operating system internet host or server host or server

  12. Client must contact server server process must first be running server must have created socket (door) that welcomes client’s contact Client contacts server by: creating client-local socket specifying IP address, port number of server process When client creates socket: client transport protocol establishes connection to the server When contacted by client, server transport protocol creates new socket for server process to communicate with client allows server to talk with multiple clients Socket Programming (cont..)

  13. Socket Programming (cont..) These are examples of functions or methods typically provided by the API library: • socket() creates a new socket of a certain socket type, identified by an integer number, and allocates system resources to it. • bind() is typically used on the server side, and associates a socket with a socket address structure, i.e. a specified local port number and IP address. • listen() is used on the server side, and causes a bound TCP socket to enter listening state. • connect() is used on the client side, and assigns a free local port number to a socket. In case of a TCP socket, it causes an attempt to establish a new TCP connection.

  14. Socket Programming (cont..) • accept() is used on the server side. It accepts a received incoming attempt to create a new TCP connection from the remote client, and creates a new socket associated with the socket address pair of this connection. • send() and recv(), or write() and read(), or recvfrom() and sendto(), are used for sending and receiving data to/from a remote socket. • close() causes the system to release resources allocated to a socket. In case of TCP, the connection is terminated.

  15. Thank you

More Related