EN
このコンテンツは設定された言語で表示できません。英語版のページが表示されます。

Disconnecting the Server

Once the server is completed receiving data from the client and sending data back to the client, the server disconnects from the client and shutdowns the socket.

Bb530744.wedge(en-us,VS.85).gifTo disconnect and shutdown a socket

  1. When the server is done sending data to the client, the shutdown function can be called specifying SD_SEND to shutdown the sending side of the socket. This allows the client to release some of the resources for this socket. The server application can still receive data on the socket.
    
    // shutdown the send half of the connection since no more data will be sent
    iResult = shutdown(ClientSocket, SD_SEND);
    if (iResult == SOCKET_ERROR) {
        printf("shutdown failed: %d\n", WSAGetLastError());
        closesocket(ClientSocket);
        WSACleanup();
        return 1;
    }
    
    
    
  2. When the client application is done receiving data, the closesocket function is called to close the socket.

    When the client application is completed using the Windows Sockets DLL, the WSACleanup function is called to release resources.

    
    // cleanup
    closesocket(ClientSocket);
    WSACleanup();
    
    return 0;
    
    
    

Complete Server Source Code

Related topics

Getting Started With Winsock
Winsock Server Application
Receiving and Sending Data on the Server
Running the Winsock Client and Server Code Sample

 

 

コミュニティの追加

追加
表示:
© 2014 Microsoft