Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Network Communications A Brief Introduction. 2 Network Communications.

Similar presentations


Presentation on theme: "1 Network Communications A Brief Introduction. 2 Network Communications."— Presentation transcript:

1 1 Network Communications A Brief Introduction

2 2 Network Communications

3 3 IP Addresses 32 bits 4 bytes Usually expressed as 4 decimal numbers in the range from 0 to 255, separated by dots Example: 192.168.1.39 (My home desktop computer) 10.9.0.21 (office laptop wireless) 127.1.1.1 local host

4 4 What is my IP address?

5 5 IP Addresses An IP address corresponds to a destination on the Internet. Typically one computer (host.) Many programs may be running on that computer and all communicating on the Internet using the same IP address. Identified by port number

6 Ports Multiplex using port numbers. 16 bit unsigned numbers 1 – 65,535 Numbers (typical, since vary by OS): 0-1023 “reserved”, must be root 1024 - 5000 “ephemeral” Above 5000 for general use ( 50,000 is specified max) Well-known, reserved services (see https://en.wikipedia.org/wiki/List_of_TCP_and_UDP _port_numbers https://en.wikipedia.org/wiki/List_of_TCP_and_UDP _port_numbers ftp 20,21 Ssh 22 http80 6

7 7 Clients and Servers Network communication is typically between a client and a server. The client initiates communication. Must know the IP address of the server and the port number of the application. Like placing a telephone call. The Server accepts requests from clients. Does not know the IP address of the client in advance. Like answering a telephone call. The same computer and program can be a server for one conversation and a client for another.

8 8 Sockets A socket is an operating system construct used by a program to perform network I/O. Similar to an open file. Originally a Unix concept. Later implemented in Windows. Network communication is between sockets. One program writes to a socket. Another program reads from a socket. The host operating systems at end points use the network to transport bytes between sockets.

9 9 Server and Client TCP/UDP IP Ethernet Adapter Server TCP/UDP IP Ethernet Adapter Clients Server and Client exchange messages over the network through a common Socket API Socket API hardware kernel space user space ports

10 10 User Datagram Protocol(UDP): An Analogy Postal Mail Single mailbox to receive messages Unreliable Not necessarily in-order delivery Each letter is independent Must address each reply Example UDP applications Multimedia, voice over IP UDP Single socket to receive messages No guarantee of delivery Not necessarily in-order delivery Datagram – independent packets Must address each packet Postal Mail Single mailbox to receive letters Unreliable Not necessarily in-order delivery Letters sent independently Must address each reply

11 Lecture 3: 9-4-0111 Transmission Control Protocol (TCP): An Analogy TCP Reliable – guarantee delivery Byte stream – in-order delivery Connection-oriented – single socket per connection Setup connection followed by data transfer Telephone Call Guaranteed delivery In-order delivery Connection-oriented Setup connection followed by conversation Example TCP applications Web, Email, Telnet

12 12 Streams vs. Datagrams TCP uses a connection between sockets to provide reliable byte stream transfer. Bytes are delivered in the order sent. UDP provides a datagram service. Each datagram is handled independently May be delivered out of order. May be lost. Both TCP and UDP use IP to transport packets across the Internet.

13 13 TCP Connections A TCP connection requires a setup phase. “Handshake” between client an server. Server listens for connection requests. Client requests connection. Server accepts connection request. Once set up, the connection is a two-way communication channel. Either party can sent bytes to the other.

14 14 socket bind() listen() accept() Server socket connect() send() recv() Client “Handshake” recv() send() Data (request) Data (reply) close() End-of-File recv() close() “well-known” port (Block until connection )

15 Talking to Yourself Both ends of a network connection can be in the same computer. Often done during development. The IP address 127.1.1.1 means "this computer“ aka localhost Looks the same to the application programs. 15

16 Server System.Net and System.Net.Sockets Required for using sockets A socket is needed to listen channel Socket.Bind Binds a socket to a port and IP IPAddress.Any: server must listen for client activity on all network interfaces Then apply listen Accept incoming clients 16

17 Server Socket.BeginAccept Begins an asynchronous operation to accept an incoming connection attempt send and receive data within a separate execution thread must create a callback method that implements the AsyncCallback delegate AsyncCallback Each client connection should be stored on a different socket After connection Send and Receive data 17

18 Client Needs to know servers IP and port Socket.Connect(serverIP,port); After connection Send and Receive data Data is transferred as a byte array Need to transform string  byte[] Encoding.ASCII.GetBytes(string) Encoding.ASCII.GetString(byte[]) 18

19 EXAMPLE 19


Download ppt "1 Network Communications A Brief Introduction. 2 Network Communications."

Similar presentations


Ads by Google