Chapter 1:

An Intro to Windows Socket (Winsock2) Programming





C & Winsock: The Kick Start programming tutorials


C & Linux Socket


Program Example Index


C#, VB .NET & C++/CLI Network Programming


Windows Device Driver Development & Program Examples


ReactOS - Windows OS Binary Compatible Open Source Project - C & C++








What do we have in this chapter?

  1. Winsock Headers and Libraries

  2. Initializing Winsock

    Error Checking and Handling

  3. Addressing a Protocol

  4. Addressing IPv4

    Internet Addresses

    Some Note

    inet_ntoa() Function

    InetNtop() Function

    InetPton() Function

    Byte Ordering

    Creating a Socket

    Connection-Oriented Communication

    Server API Functions

    Binding, bind()

    Listening, listen()

    Accepting Connections, accept()

  5. Client API Functions

  6. TCP States


  7. Data Transmission

  8. send() and WSASend()


    Out-of-Band Data

    recv() and WSARecv()


    Stream Protocols

    Scatter-Gather I/O

    Breaking the Connection



    TCP Receiver/Server With select() Example

  9. TCP Sender/client Program Example

  10. Testing the TCP Client and Server Programs

    Testing the TCP Client and Server Programs in Private Network

  11. Connectionless Communication

  12. Receiver


  13. Running Both the UDP Receiver/Server and UDP Sender/Client

  14. Testing the UDP Client and select Server Programs in Private Network

    Message-Based Protocols

    Releasing Socket Resources

    Miscellaneous APIs




    Windows CE





In this chapter, we presented the core Winsock functions that are required for connection-oriented and connectionless communication using the TCP and UDP protocols specifically. For connection-oriented communication, we demonstrated how to accept a client connection and how to establish a client connection to a server. We covered the semantics for session-oriented data-send operations and data-receive operations. For connectionless communication, we also described how to send and receive data. Since this chapter was designed to introduce the core Winsock APIs, we did not address network programming performance considerations. Later, we will address performance issues and introduce the Microsoft Winsock extensions TransmitFile(), TransmitPackets(), AcceptEx(), GetAcceptExSockaddrs(), ConnectEx(), DisconnectEx(), and WSARecvMsg(), which can help you write high performance, scalable Winsock applications. Our discussions so far have demonstrated using Winsock with just the IPv4 protocol.







Custom Search



< Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7 | Chap 2: Protocol Characteristics >


Share and email to your beloved friends and foes: