1 / 6

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. Socket programming with UDP. Why UDP?.

sukey
Download Presentation

Socket programming with UDP

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. 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 Socket programming with UDP

  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 Client Recv Send Server Socket Client Socket Send Recv Client Socket Client Socket

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

  5. UDP Sockets in C++/CLI Server Client • UdpClient ^ client = gcnew UdpClient( 12345 ) • IPEndPoint ^receivePoint = gcnew IPEndPoint( IPAddress::Any, 0 ); • array<Byte>^ 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<Byte>^ data = client->Receive( receivePoint );

  6. An Example

More Related