Windows Socket: Course: COMP6120 - Network Programming Year: 2016

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 24

Course : COMP6120 - Network Programming

Year : 2016

Windows Socket

Session 11
Learning Outcome

• Demonstrate a client-server program using Winsock


Topics

• What is Socket ?
• What is Winsock ?
• The Socket History
• Winsock History
• Supported Programming Models
• Elements of Winsock Programming
• General Program Flow
• Iterative Server pada Windows
• Concurrent Server pada Windows
WinSock

• What is Socket?
– Socket is is a programming model originally designed for
network programming under UNIX operating systems.
• What is Winsock?
– Winsock stands for Windows Socket;
– An Application Programming Interface for network
programming under the Microsoft Windows operating
systems.
– It is modeled after UNIX Socket but with platform-specific
features added.
WinSock
WinSock
WinSock
WinSock

• Supported Programming Models


– Synchronous Model
– Asynchronous Model
• Synchronous Model
– Makes use of blocking-mode I/O function calls.
– What is Blocking I/O?
• Guaranteed either function completed successfully
or failed upon function return
• The calling code has to wait (i.e. block) for the
function to complete before continuing execution
WinSock

• Asynchronous Model
– Makes use of non-blocking-mode I/O function calls.
• What is Non-Blocking I/O?
– Guaranteed function will return immediately:
– The calling code has to check if the function has completed before
return.
– If not, the calling code will have to handle that itself.(e.g. check at a
later time, call the function again, wait for asynchronous event to
trigger, etc.)
Elements of
Winsock Programming
Elements of
Winsock Programming
• BSD-Style Winsock Functions
– Core functions
• accept, bind, closesocket, connect, listen, recv,
recvfrom, select, send, sendto, Shutdown,
socket
– Auxiliary functions
• Getpeername, Getsockname, Getsockopt,
ioctlsocket
– Utility functions
• htonl, htons, inet_addr, inet_ntoa, ntohl, ntohs
Elements of
Winsock Programming
• Windows-Specific Winsock Functions
– Core functions
• WSAStartup, WSACleanup, WSAAsyncGettByn,
WSAAsyncSelect, WSACancelAsyncRequest,
WSAConnect,WSAIoctl, WSARecv, WSARecvFrom, WSASend,
WSASendTo, WSASocket
– Auxiliary functions
• WSADuplicateSocket, WSAEnumNetworkEvents,
WSAEnumProtocols, WSAGetLastError, WSAGetQOSByName,
WSAHtonl, WSAHtons, WSAJoinLeaf, WSANtohl, WSANtohs,
WSAProviderConfigChange, WSASetLastError
– Supporting functions
• WSACloseEvent, WSACreateEvent, WSAEventSelect,
WSAGetOverlappedResult, WSAResetEvent, WSASetEvent,
WSAWaitForMultipleEvents
General Program Flow
General Program Flow
General Program Flow
Iterative Server
Concurrent Server
Concurrent Server

• I/O Models for Concurrent Servers


– Synchronous/Blocking Mode I/O
• Multi-threading (Win32 only)
• Similar to the UNIX fork( ) multiple-process
model.
– Asynchronous/Non-Blocking Mode I/O
• Message-driven (All Windows versions)
• Overlapped I/O (Win32 only)
– Socket handle signalling
– Windows event object signalling
– I/O completion routines
– I/O Completion Ports (Windows NT only)
Concurrent Server
Concurrent Server
Concurrent Server
Concurrent Server
Build Client-Server program using Windows Socket

Bina Nusantara University 23


References

• TCP/IP Sockets in C, chapter 2 & 3


• http://tangentsoft.net/wskfaq/
• http://www.codeproject.com/Articles/1891/Beginning-
Winsock-Programming-Simple-TCP-server
• Richard W, Unix Network Programming, Volume 1:
The Sockets Networking API, 2003

You might also like