1 pertemuan 9 windows socket ( winsock ) matakuliah: h0483 – network programming tahun: 2008...
TRANSCRIPT
1
Pertemuan 9 Windows Socket
( WinSock )
Matakuliah : H0483 – Network Programming
Tahun : 2008
Versi : 2.0
2
Learning Outcomes
Pada akhir pertemuan ini, diharapkan mahasiswa
akan mampu :
• Mendemokan program aplikasi pada sistem operasi windows dengan menggunakan Windows Socket.
3
Outline Materi
• 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
4
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.
8
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
9
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.)
11
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
12
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
16
Online References
• References– The Winsock 1.1 and 2.0 Specifications – Winsock Resource Centre at
http://www.winsock.com– Windows socket programming resources at
http://www.sockets.com– Visual C++ On-Line Help and Programming
Reference
19
Concurrent Servers
• 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)