Presentation is loading. Please wait.

Presentation is loading. Please wait.

IEG4180 Tutorial 3 Shaoquan Zhang. Announcement The deadline of the project 1 is extended to 11pm, 12/02/2011 Follow the requirement of the marking scheme.

Similar presentations


Presentation on theme: "IEG4180 Tutorial 3 Shaoquan Zhang. Announcement The deadline of the project 1 is extended to 11pm, 12/02/2011 Follow the requirement of the marking scheme."— Presentation transcript:

1 IEG4180 Tutorial 3 Shaoquan Zhang

2 Announcement The deadline of the project 1 is extended to 11pm, 12/02/2011 Follow the requirement of the marking scheme

3 Outline Stream socket programming I/O modes in Unix

4 Stream Socket Programming Stream socket Q: When is the three-way handshake happened? A: When the client calls the function connect(), the TCP connection is built before the accept(). The function accept() selects one from the established connection queue.

5 TCP Connection Backlog TCP Connection Queue – For a given listening socket, the kernel maintains two queues for client sockets: An incomplete connection queue: three-way handshake is not completed yet; A completed connection queue: three-way handshake is completed. – listen(socket s, int backlog) backlog: the maximum of the sum of two queue lengths Problem: SYN attack

6 Accept() By default, when the completed queue is empty, the function will be blocked. Methods: – poll() : accept() becomes non-blocking – select(): accept() is called only when the completed queue is not empty – Multithread – Message driven

7 Message-driven Accept() SOCKET s=socket(); bind(); WSAAsyncSelect(s, m_hWnd, wMsg, FD_ACCEPT); //turn the socket s into a message-driven socket //m_hWnd: handle to window that will process the message //wMsg: message identifier; FD_ACCEPT: events to handle listen(s, 5);

8 Message Flow

9 WindowProc() HRESULT CNetProbeDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { if(message==wMsg) { SOCKET s = (SOCKET)wParam; int event = WSAGETSELECTEVENT(lParam); switch(event){ case FD_ACCEPT: OnAccept(s); break; case FD_READ: OnRead(s); //receive data break; } } return CDialog::WindowProc(message, wParam, lParam); } message events to handle void CNetProbeDlg::OnAccept(SOCKET s) { SOCKET newsfd = accept(s,…); WSAAsyncSelect(newsfd, m_hWnd, wMsg, FD_READ); //turn the new socket into a message-driven one; handle the recv() }

10 Add WindowProc() class review -> dialog class propertyoverrides

11 Unix I/O Modes Blocking I/O Non-blocking I/O I/O multiplexing (select and poll) Asynchronous I/O For a socket input operation, there are two steps: 1. wait data to arrive 2. copy data from kernel’s buffer to the process

12 Blocking I/O Acknowledgement: following pictures come from UNIX Networking Programming

13 Non-blocking I/O

14 I/O Multiplexing

15 Asynchronous I/O

16 Backup Host AHost B


Download ppt "IEG4180 Tutorial 3 Shaoquan Zhang. Announcement The deadline of the project 1 is extended to 11pm, 12/02/2011 Follow the requirement of the marking scheme."

Similar presentations


Ads by Google