Top Banner
1 Pertemuan 9 Windows Socket ( WinSock ) Matakuliah : H0483 – Network Programming Tahun : 2008 Versi : 2.0
25

1 Pertemuan 9 Windows Socket ( WinSock ) Matakuliah: H0483 – Network Programming Tahun: 2008 Versi: 2.0.

Dec 14, 2015

Download

Documents

Allan Scholer
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 1 Pertemuan 9 Windows Socket ( WinSock ) Matakuliah: H0483 – Network Programming Tahun: 2008 Versi: 2.0.

1

Pertemuan 9 Windows Socket

( WinSock )

Matakuliah : H0483 – Network Programming

Tahun : 2008

Versi : 2.0

Page 2: 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.

Page 3: 1 Pertemuan 9 Windows Socket ( WinSock ) Matakuliah: H0483 – Network Programming Tahun: 2008 Versi: 2.0.

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

Page 4: 1 Pertemuan 9 Windows Socket ( WinSock ) Matakuliah: H0483 – Network Programming Tahun: 2008 Versi: 2.0.

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.

Page 5: 1 Pertemuan 9 Windows Socket ( WinSock ) Matakuliah: H0483 – Network Programming Tahun: 2008 Versi: 2.0.

5

WinSock

Page 6: 1 Pertemuan 9 Windows Socket ( WinSock ) Matakuliah: H0483 – Network Programming Tahun: 2008 Versi: 2.0.

6

WinSock

Page 7: 1 Pertemuan 9 Windows Socket ( WinSock ) Matakuliah: H0483 – Network Programming Tahun: 2008 Versi: 2.0.

7

WinSock

Page 8: 1 Pertemuan 9 Windows Socket ( WinSock ) Matakuliah: H0483 – Network Programming Tahun: 2008 Versi: 2.0.

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

Page 9: 1 Pertemuan 9 Windows Socket ( WinSock ) Matakuliah: H0483 – Network Programming Tahun: 2008 Versi: 2.0.

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.)

Page 10: 1 Pertemuan 9 Windows Socket ( WinSock ) Matakuliah: H0483 – Network Programming Tahun: 2008 Versi: 2.0.

10

Elements of Winsock Programming

Page 11: 1 Pertemuan 9 Windows Socket ( WinSock ) Matakuliah: H0483 – Network Programming Tahun: 2008 Versi: 2.0.

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

Page 12: 1 Pertemuan 9 Windows Socket ( WinSock ) Matakuliah: H0483 – Network Programming Tahun: 2008 Versi: 2.0.

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

Page 13: 1 Pertemuan 9 Windows Socket ( WinSock ) Matakuliah: H0483 – Network Programming Tahun: 2008 Versi: 2.0.

13

General Program Flow

Page 14: 1 Pertemuan 9 Windows Socket ( WinSock ) Matakuliah: H0483 – Network Programming Tahun: 2008 Versi: 2.0.

14

General Program Flow

Page 15: 1 Pertemuan 9 Windows Socket ( WinSock ) Matakuliah: H0483 – Network Programming Tahun: 2008 Versi: 2.0.

15

General Program Flow

Page 16: 1 Pertemuan 9 Windows Socket ( WinSock ) Matakuliah: H0483 – Network Programming Tahun: 2008 Versi: 2.0.

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

Page 17: 1 Pertemuan 9 Windows Socket ( WinSock ) Matakuliah: H0483 – Network Programming Tahun: 2008 Versi: 2.0.

17

Iterative Server pada Windows

Page 18: 1 Pertemuan 9 Windows Socket ( WinSock ) Matakuliah: H0483 – Network Programming Tahun: 2008 Versi: 2.0.

18

Concurrent Server pada Windows

Page 19: 1 Pertemuan 9 Windows Socket ( WinSock ) Matakuliah: H0483 – Network Programming Tahun: 2008 Versi: 2.0.

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)

Page 20: 1 Pertemuan 9 Windows Socket ( WinSock ) Matakuliah: H0483 – Network Programming Tahun: 2008 Versi: 2.0.

20

Concurrent Server pada Windows

Page 21: 1 Pertemuan 9 Windows Socket ( WinSock ) Matakuliah: H0483 – Network Programming Tahun: 2008 Versi: 2.0.

21

Concurrent Server pada Windows

Page 22: 1 Pertemuan 9 Windows Socket ( WinSock ) Matakuliah: H0483 – Network Programming Tahun: 2008 Versi: 2.0.

22

Concurrent Server pada Windows

Page 23: 1 Pertemuan 9 Windows Socket ( WinSock ) Matakuliah: H0483 – Network Programming Tahun: 2008 Versi: 2.0.

23

Concurrent Server pada Windows

Page 24: 1 Pertemuan 9 Windows Socket ( WinSock ) Matakuliah: H0483 – Network Programming Tahun: 2008 Versi: 2.0.

24

Concurrent Server pada Windows

Page 25: 1 Pertemuan 9 Windows Socket ( WinSock ) Matakuliah: H0483 – Network Programming Tahun: 2008 Versi: 2.0.

25

Latihan

• Buat Program Echo Server dan program client nya pada Windows dengan menggunakan Winsock. Bahasa Pemrograman yang digunakan bebas.