Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 2b Sockets Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.

Similar presentations


Presentation on theme: "Lecture 2b Sockets Erick Pranata © Sekolah Tinggi Teknik Surabaya 1."— Presentation transcript:

1 Lecture 2b Sockets Erick Pranata © Sekolah Tinggi Teknik Surabaya 1

2 » Do not have to “connect“ before sending messages » Preserve message boundaries » Best effort: message may lose, may scrambled 2 © Sekolah Tinggi Teknik Surabaya

3 » Efficiency ˃Single request message and single response message » Flexibility ˃Minimal overhead platform 3 © Sekolah Tinggi Teknik Surabaya

4 4

5 UdpClient.Send()UdpClient.Receive() 5 © Sekolah Tinggi Teknik Surabaya

6 packet from A packet from B packet from A 6 © Sekolah Tinggi Teknik Surabaya

7 7 » Maximum message length: 65,507 bytes (65 KB)

8 » Construct an instance of UdpClient, optionally specifying the local address and port. » Communicate by sending and receiving datagrams (byte arrays) using the Send() and Receive() methods of UdpClient. » When finished, deallocate the socket using the Close() method of UdpClient. 8 © Sekolah Tinggi Teknik Surabaya

9 » Construct an instance of UdpClient, specifying the local port. The server is now ready to receive datagrams from any client. » Receive a packet using the Receive() method of UdpClient. The Receive() method takes a reference to an IPEndPoint instance as an argument, and when the call returns the IPEndPoint contains the client’s address so we know where to send the reply. » Communicate by sending and receiving datagram packets using the Send() and Receive() methods of UdpClient. » When finished, deallocate the socket using the Close() method of UdpClient. 9 © Sekolah Tinggi Teknik Surabaya

10 10

11 » Call the Socket constructor: The constructor specifies the address type, socket type, and protocol type. » Call the Socket Connect() method: Connect() takes an IPEndPoint argument that represents the server to connect to. » Send and receive data: Using the Socket Send() and Receive() calls. » Close the socket: Using the Socket Close() method. 11 © Sekolah Tinggi Teknik Surabaya

12 » Call the Socket constructor: The constructor specifies the address type, socket type, and protocol type. » Call the Socket Bind() method: Bind() associates the socket with a local address and port number. » Call the Socket Listen() method: Listen() takes an integer argument representing the number of connections allowed to queue, and starts listening for incoming connections. » Repeatedly: ˃ Call the Socket Accept() method to accept an incoming connection: Accept() takes no arguments and returns a Socket instance representing the remote client socket. ˃ Receive and send data: Using the accepted client Socket instance, use its Receive() and Send() methods to transfer data. ˃ Close the client socket: Using the Socket Close() method. » Close the socket: Using the Socket Close() method. 12 © Sekolah Tinggi Teknik Surabaya

13 » Socket Options.pdf Socket Options.pdf 13 © Sekolah Tinggi Teknik Surabaya

14 » Send the echo string to the server. » Block on Receive() for up to three seconds, starting over (up to five times) if the reply is not received before the timeout. » Terminate the client. 14 © Sekolah Tinggi Teknik Surabaya

15 » int len = s.Receive(buf, 0, buf.Length, SocketFlags.Peek); » len = s.Receive(buf, 0, buf.Length, SocketFlags.None); 15 © Sekolah Tinggi Teknik Surabaya

16 » Answer these and write it into an essay.these » Submission due: Tuesday, 1 April 2014 (printed) 16 © Sekolah Tinggi Teknik Surabaya

17 » David Makofske, Michael J. Donahoo, Kenneth L. Calvert, TCP/IP Sockets in C#: Practical Guide for Programmers, Morgan Kaufmann, 2004 17 © Sekolah Tinggi Teknik Surabaya


Download ppt "Lecture 2b Sockets Erick Pranata © Sekolah Tinggi Teknik Surabaya 1."

Similar presentations


Ads by Google