通过TCP在winsock中发送基本的1D数组

时间:2014-01-12 02:34:14

标签: c sockets winsock

我尝试使用Winsock send()函数通过TCP连接发送长度为10的uint8_t数组。好像它不发送任何东西。这个程序有什么问题?

#define DEFAULT_BUFLEN 10

int main(int argc , char *argv[])
{
WSADATA wsa;
SOCKET server_socket, client_socket;
struct sockaddr_in server_addr, client_addr;
int c, iResult;
char sendbuf [DEFAULT_BUFLEN];
int sendbuflen = DEFAULT_BUFLEN;
uint8_t* p;

// Send string to client
p = (uint8_t*)sendbuf;

p[0] = 67;
p[1] = 143;
p[2] = 222;
p[3] = 134;
p[4] = 217;
p[5] = 97;
p[6] = 17;
p[7] = 16;
p[8] = 181;
p[9] = 137;
iResult = send(client_socket, sendbuf, sendbuflen, 0);

// shutdown the connection since no more data will be sent
if (shutdown(client_socket, SD_SEND) == SOCKET_ERROR) 
{
    printf("Shutdown failed. Error Code : %d\n", WSAGetLastError());
    iResult = 1;
}

closesocket(client_socket);
WSACleanup();

return iResult;
} 

0 个答案:

没有答案