Presentation is loading. Please wait.

Presentation is loading. Please wait.

Windows Network Programming ms-help://MS.MSDNQTR.2004JAN.1033/winsock/winsock/windows_sockets_start_page_2.htm 井民全.

Similar presentations


Presentation on theme: "Windows Network Programming ms-help://MS.MSDNQTR.2004JAN.1033/winsock/winsock/windows_sockets_start_page_2.htm 井民全."— Presentation transcript:

1 Windows Network Programming ms-help://MS.MSDNQTR.2004JAN.1033/winsock/winsock/windows_sockets_start_page_2.htm 井民全

2 Introduction Purpose Purpose Create advanced Internet, intranet, and other network- capable applications Create advanced Internet, intranet, and other network- capable applications provided network capabilities of multicasting and Quality of Service (QOS) provided network capabilities of multicasting and Quality of Service (QOS) Following the WOSA Model Following the WOSA Model Windows Open System Architecture (WOSA) Windows Open System Architecture (WOSA) the interfaces for connecting front-end applications with back-end services the interfaces for connecting front-end applications with back-end services WOSA defines an abstraction layer to heterogeneous computing resources through the WOSA set of APIs WOSA defines an abstraction layer to heterogeneous computing resources through the WOSA set of APIs

3 Winsock defines a standard service provider interface (SPI) between API. (from WS2.dll) Winsock defines a standard service provider interface (SPI) between API. (from WS2.dll)

4 Winsock Programming Considerations The major feature changed from Winsock 1 The major feature changed from Winsock 1 FeaturesDescription Socket handles A socket handle can be used as file handle. Simultaneous access to multiple transport protocols Application can simultaneous access to a number of installed transport protocols Protocol-independent name resolution * Server can register its exists within the namespaces * Client can find the service within a namespace and obtain information ReadFile, WriteFile, etc.

5 Overlapped I/O with scatter/gather IO Ex: the header components can be automatically split off into separate buffer, leaving the message body pure Protocol-independent multicast and multipoint

6 Scatter-gather I/O Before NT4.0 SP2, Before NT4.0 SP2, all data access for disk had to be in a contiguous area of memory all data access for disk had to be in a contiguous area of memory Scatter-gather I/O allows a read/write to transfer data in to or out of discontiguous area of memory. Scatter-gather I/O allows a read/write to transfer data in to or out of discontiguous area of memory. Windows 2000 support scatter-gather I/O Windows 2000 support scatter-gather I/O If a read transferred in 64 KB of data, the request had to specify the address of a contiguous area of 64 KB

7 Asynchronous I/O an AP requests a read/write operation from OS immediately returns control to the AP. an AP requests a read/write operation from OS immediately returns control to the AP. the AP can then perform addition work and later test to see if read/write has completed. the AP can then perform addition work and later test to see if read/write has completed. the operating system do not return control to the AP until the read/write completes. Synchronous I/O

8 Overlapped I/O Overlapped send and receive calls return immediately. Overlapped send and receive calls return immediately. Return value = 0 Return value = 0 I/O operation completed immediately and the corresponding completion indication has already occurred. I/O operation completed immediately and the corresponding completion indication has already occurred. Return value =WSA_IO_PENDING Return value =WSA_IO_PENDING the overlapped operation has been successfully initiated. the overlapped operation has been successfully initiated. a subsequent indication will be provided when a subsequent indication will be provided when send buffer have been consumed send buffer have been consumed receive buffer are filled receive buffer are filled associated event object has been signaled, or the completion routine has called. Any other error code indicates ERROR

9 Overlapped I/O Both send and receive operation can be overlapped. Both send and receive operation can be overlapped. The receive functions can be invoked multiple times to post receive buffer in preparation for incoming data. Read The send functions can be invoked multiple times to queue up multiple buffers to be sent. Write

10 Winsock and the OSI Model Winsock operates at the session layer interface to the transport layer Winsock operates at the session layer interface to the transport layer ms-help://MS.MSDNQTR.2004JAN.1033/wcecomm/html/_wcesdk_Windows_Networking_and_the_OSI_Model.htm

11 Create a Basic Winsock Application Link to the Winsock library file, WS2_32.lib Link to the Winsock library file, WS2_32.lib 1 2

12 WSAStartup Initiates use of WS2_32.dll by a process Initiates use of WS2_32.dll by a process [in] Highest version of WinSock support Ex: MAKEWORD(2,2) [out] receive the detail of WinSock implementation Return Value: return zero if successful

13 socket function Cause a socket descriptor and located related resource to a specific transport-service provider Cause a socket descriptor and located related resource to a specific transport-service provider Winsock will utilize the first available service provider. Winsock will utilize the first available service provider. overlapped attribute is default overlapped attribute is default You can use WSASocket to create nonoverlapped socket You can use WSASocket to create nonoverlapped socket All functions allow overlapped operation also support nonoverlapped usage on an overlapped socket All functions allow overlapped operation also support nonoverlapped usage on an overlapped socket WSASend, WSARecv, WSASendTo, WSARecvFrom, WSAIoctl


Download ppt "Windows Network Programming ms-help://MS.MSDNQTR.2004JAN.1033/winsock/winsock/windows_sockets_start_page_2.htm 井民全."

Similar presentations


Ads by Google