Matakuliah : H0483 – Network Programming Tahun : 2008 Versi : 2.0 Pertemuan 9 Windows Socket ( WinSock ) 1 Learning Outcomes Pada akhir pertemuan ini, diharapkan mahasiswa akan mampu : • Mendemokan program aplikasi pada sistem operasi windows dengan menggunakan Windows Socket. 2 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 3 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. 4 WinSock 5 WinSock 6 WinSock 7 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 8 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.) 9 Elements of Winsock Programming 10 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 11 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 12 General Program Flow 13 General Program Flow 14 General Program Flow 15 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 16 Iterative Server pada Windows 17 Concurrent Server pada Windows 18 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) 19 Concurrent Server pada Windows 20 Concurrent Server pada Windows 21 Concurrent Server pada Windows 22 Concurrent Server pada Windows 23 Concurrent Server pada Windows 24 Latihan • Buat Program Echo Server dan program client nya pada Windows dengan menggunakan Winsock. Bahasa Pemrograman yang digunakan bebas. 25
© Copyright 2026 Paperzz