Presentation is loading. Please wait.

Presentation is loading. Please wait.

Socket programming with UDP UDP: no “connection” between client & server sender explicitly attaches IP destination address and port # to each packet receiver.

Similar presentations


Presentation on theme: "Socket programming with UDP UDP: no “connection” between client & server sender explicitly attaches IP destination address and port # to each packet receiver."— Presentation transcript:

1 Socket programming with UDP UDP: no “connection” between client & server sender explicitly attaches IP destination address and port # to each packet receiver extracts sender IP address and port# from received packet UDP: transmitted data may be lost or received out-of-order

2 Why UDP? When receiving a msg, all the data can be extracted directly. Can extract sender’s IP and Port#. UDP provides unreliable transfer of groups of bytes (“datagrams”) between client and server –loss, out of order Applications (tolerant loss and mis-order )? –Games? Audio/Video? –Additional code maybe needed.

3 UDP Socket Communications Server Socket Client Socket Server Client RecvSend Recv Client Socket

4 Client/server socket interaction: UDP Close client read datagram from IPEndPoint ^receivePoint = gcnew IPEndPoint( IPAddress::Any, 0 ); array ^ data = client->Receive( receivePoint ); create socket: UdpClient ^ client = gcnew UdpClient( 0 ) ; Create datagram with serverIP and port=x; send datagram via client->Send( data, data->Length, L“ serverIP ", 12345 ); create socket, port= x: UdpClient ^ client = gcnew UdpClient( 12345 ); IPEndPoint ^receivePoint = gcnew IPEndPoint( IPAddress::Any, 0 ); read datagram from array ^ data = client- >Receive( receivePoint ); write reply to client->Send( data, data->Length, receivePoint ); specifying client address, port number server (running on serverIP ) client

5 UDP Sockets in C++/CLI UdpClient ^ client = gcnew UdpClient( 12345 ) IPEndPoint ^receivePoint = gcnew IPEndPoint( IPAddress::Any, 0 ); array ^ data = client- >Receive( receivePoint ); client->Send( data, data- >Length, receivePoint ); UdpClient ^ client = gcnew UdpClient( 0 ) ; client->Send( data, data- >Length, L“127.0.0.1", 12345 ); IPEndPoint ^receivePoint = gcnew IPEndPoint( IPAddress::Any, 0 ); array ^ data = client- >Receive( receivePoint ); ServerClient

6 An Example


Download ppt "Socket programming with UDP UDP: no “connection” between client & server sender explicitly attaches IP destination address and port # to each packet receiver."

Similar presentations


Ads by Google