仍嘗試理解send()和recv()函數。爲什麼這不起作用?沒有在服務器輸出上打印出來(除了一些測試「cout」)基本Send()和Recv()TCP服務器和客戶端C++
這基本上是我搞亂的代碼的一部分。
客戶端:
char *mesg_to_send;
Socket servSock;
mesg_to_send = The King is Dead!";
// Establish the connection to the echo server
if(connect(servSock, (struct sockaddr *) &srvr_addr, sizeof(srvr_addr)) < 0)
DieWithError("connect() failed");
send(servSock, (char*) mesg_to_send, sizeof(int), 0);
服務器端:
char *sentence;
Socket clnt_socket;
// Wait for the client to connect
if((clnt_socket = accept(srvr_socket, (struct sockaddr *) &clnt_addr, &addr_len)) < 0)
DieWithError("accept() failed");
recv(clnt_socket, (char*) sentence, sizeof(int), 0);
cout << sentence;