Full Transcript

Network Programming Sockets Programming Lecture (1) 1 Sockets  Socket: is a device or point host or host or server server in a wall where yo...

Network Programming Sockets Programming Lecture (1) 1 Sockets  Socket: is a device or point host or host or server server in a wall where you can connect electrical controlled by app developer equipment to the power process process supply socket socket  A hollow part or piece for TCP with Internet TCP with receiving and buffers, buffers, variables variables holding/transmitting some part or thing. controlled by OS 2 Sockets  Socket in Networking: host or host or server server process sends/receives messages to/from its controlled by app developer socket process process  socket analogous to door socket socket  sending process shoves TCP with Internet TCP with buffers, message out door buffers, variables variables  sending process relies on transport infrastructure controlled on other side of door which by OS brings message to socket at receiving process 3 Socket programming Goal: learn how to build client/server application that communicate using sockets socket a host-local, application-created, OS-controlled interface (a “door”) into which application process can both send and receive messages to/from another application process 4 Socket programming API: application programming interface (API) is a set of standard function calls that can be used in an application. They allow programmers to add Internet communication to their products. A client/server architecture is mandatory for BSD sockets Socket API  introduced in BSD4.1 UNIX, Socket API 1981  explicitly created, used, is a collection of socket calls that released by apps enable you to perform the following primary communication  client/server paradigm functions between application  two types of transport programs: Set up and establish service via socket API: connections to other users on the  unreliable datagram network. Send and receive data to  reliable, byte stream- and from other users. Close down oriented connections 5 Socket programming reliable, byte stream-oriented : The reliable byte stream is a common service paradigm in computer networking; it refers to a byte stream in which the bytes which emerge from the communication channel at the recipient are exactly the same, and in the same order, as they were when the sender inserted them into the channel unreliable datagram A dedicated connection is established between the source and destination end nodes, and message transfer is carried out without a transmission guarantee. Errors (including sequence errors) are detected and logged and are not informed back to the source end node. 6 Socket-programming using TCP Socket: a door between application process and end- end-transport protocol (UDP or TCP) TCP service: reliable transfer of bytes from one process to another controlled by controlled by process application application process developer developer socket socket TCP with TCP with controlled by controlled by buffers, operating operating buffers, internet system system variables variables host or host or server server 7 Socket-programming 8 Socket programming with TCP 1-Client must contact server  4- When contacted by  server process must first client, server TCP creates be running new socket for server  server must have created process to communicate with socket (door) that client welcomes client’s contact  allows server to talk with multiple clients 2-Client contacts server by:  source port numbers  creating client-local TCP used to distinguish socket clients  specifying IP address, port TCP application viewpoint number of server process TCP provides reliable, in-order  3- When client creates transfer of bytes (“pipe”) socket: client TCP between client and server establishes connection to server TCP 9 Sockets Types  your applications still can use the built-in socket interfaces. The Network Component has integrated:  The BSD Socket (Berkeley Software Distribution or Berkeley Standard Distribution - (BSD) is a discontinued operating system based on Research Unix) API enables BSD compliant communication over TCP/IP.  TCP Sockets support reliable IP communication using the Transmission Control Protocol (TCP).  UDP Sockets provide simple IP communication using the User Datagram Protocol (UDP). 10 Stream jargon  A stream is a sequence of characters that flow into or out of a process.  An input stream is attached to some input source for the process, e.g., keyboard or socket.  An output stream is attached to an output source, e.g., monitor or socket. 11 Socket programming with TCP keyboard monitor Example client-server app: 1) client reads line from standard input (inFromUser inFromUser input stream stream) , sends to server via Client socket (outToServer Process process stream) 2) server reads line from socket 3) server converts line to uppercase, sends back to inFromServer outToServer client output input stream stream 4) client reads, prints modified line from socket client TCP clientSocket (inFromServer stream) socket TCP socket to network from network 12 Client/server socket interaction: TCP Server (running on hostid) Client create socket, port=x, for incoming request: welcomeSocket = ServerSocket() TCP create socket, wait for incoming connection request connection setup connect to hostid, port=x connectionSocket = clientSocket = welcomeSocket.accept() Socket() send request using read request from clientSocket connectionSocket write reply to connectionSocket read reply from clientSocket close connectionSocket close clientSocket 13 BSD Socket  client/server architecture is mandatory for BSD sockets. Using TCP, a host listens for incoming connection requests. Upon accepting an incoming request, data can be transferred between the hosts. UDP can also be used to establish a connection.  As you can see, BSD sockets is not a stand-alone socket solution, but it is an API that relies on other socket communication for huge data exchange. Thus, you always need to add TCP and UDP to your project if you wish to use BSD sockets. 14 communication flow using BSD sockets with TCP 15

Use Quizgecko on...
Browser
Browser