44. 44
UDP Sockets
Are used for connection-less protocol
Messages are not guaranteed
Are supported in Java technology through the
DatagramSocket and DatagramPacket classes
45. 45
The DatagramPacket
DatagramPacket has two constructors: one for receiving data
and one for sending data.
DatagramPacket(byte [] recvBuf, int readLength)
DatagramPacket(byte [] sendBuf, int sendLength,
InetAddress iaddr, int iport)
46. 46
The DatagramSocket
DatagramSocket has three constructors:
– DatagramSocket()
– DatagramSocket(int port)
– DatagramSocket(int port, InetAddress iaddr)
53. 53
Дасгал: Using Socket Programming
Exercise objective:
– Gain experience using sockets by implementing a client and
server which communicate using sockets
Tasks:
– Create sockets
– Use a multithreaded server
54. 54
Өөрийн явцыг шалга
Develop code to set up network connection
Understand TCP/IP and UDP protocol
Use ServerSocket and Socket classes for implementing
TCP/IP client and servers
Use DatagramPacket and DatagramSocket for effecting a
UDP-based network communication