send function(Windows)

2687 단어

SOCKET


실질은 내부 핵 대상의 문맥이다.socket을 만드는 것은 시스템 내부에 핵 대상을 만드는 것입니다.

send


The Windows Sockets send function sends data on a connected socket.
int send (SOCKET s, const char FAR * buf, int len, int flags); 

Parameters
  • s [in] A descriptor identifying a connected socket.
  • buf [in] A buffer containing the data to be transmitted.
  • len [in] The length of the data in buf.
  • flags [in] An indicator specifying the way in which the call is made.

  • Remarks
  • outgoing data The send function is used to write outgoing data on a connected socket.
  • send completion The successful completion of a send does not indicate that the data was successfully delivered. If no buffer space is available within the transport system to hold the data to be transmitted, send will block unless the socket has been placed in a nonblocking mode. On nonblocking stream oriented sockets, the number of bytes written can be between 1 and the requested length, depending on buffer availability on both client and server machines.
  • message data is too long For message-oriented sockets, care must be taken not to exceed the maximum packet size of the underlying provider, which can be obtained by using getsockopt to retrieve the value of socket option SO_MAX_MSG_SIZE. If the data is too long to pass atomically through the underlying protocol, the error WSAEMSGSIZE is returned, and no data is transmitted.

  • Return Values
    If no error occurs, send returns the total number of bytes sent, which can be less than the number indicated by len for nonblocking sockets. Otherwise, a value of SOCKET_ERROR is returned, and a specific error code can be retrieved by calling WSAGetLastError.
    Error Codes
  • WSANOTINITIALISED A successful WSAStartup must occur before using this function.
  • WSAEWOULDBLOCK The socket is marked as nonblocking and the requested operation would block.
  • WSAEMSGSIZE The socket is message oriented, and the message is larger than the maximum supported by the underlying transport.
  • WSAETIMEDOUT The connection has been dropped, because of a network failure or because the system on the other end went down without notice.

  • Using Example

    int iResult = send(ConnectSocket, sendbuf, (int)strlen(sendbuf), 0); 
    if (SOCKET_ERROR == iResult) 
    { 
        wprintf(L"send failed with error: %d
    ", WSAGetLastError()); closesocket(ConnectSocket); WSACleanup(); return 1; }

    References https://msdn.microsoft.com/en-us/library/ms740149(VS.85).aspx

    좋은 웹페이지 즐겨찾기