O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

As with the TCP server, the UDP server can be created with the help of the net package. With the use of the ListenPacket function, the PacketConn is created. 

The PacketConn does not implement the Reader and Writer interface as the TCPConn. For reading the received packet, the ReadFrom method should be used. The ReadFrom method blocks until the packet is received. After this, the Addr of the client is returned (remember the UDP is not connection-based ). To respond to the client, the WriteTo method of PacketConn could be used; this consumes the message and the Addr, which is the client Addr, in this case.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required