修改自網路:
#include #include #include #pragma comment(lib, "ws2_32.lib")
int client(void);
unsigned short port;
int main(int argc, char *argv)
int client(void)
if ((isockcliid = socket(af_inet, sock_stream, 0)) < 0)
stcliaddr.sin_family = af_inet;
stcliaddr.sin_addr.s_un.s_addr = htonl(inaddr_any);
stcliaddr.sin_port = htons(port);
if ((bind(isockcliid, (struct sockaddr *)&stcliaddr, sizeof (struct sockaddr_in))) < 0)
stservaddr.sin_family = af_inet;
stservaddr.sin_addr.s_un.s_addr = inet_addr("192.168.7.104");
stservaddr.sin_port = htons(8001);
if (connect(isockcliid, (struct sockaddr *)&stservaddr, sizeof (struct sockaddr_in)) < 0)
send(isockcliid, buff, strlen(buff), 0);
memset(buff, 0, sizeof (buff));
recv(isockcliid, buff, sizeof (buff), 0);
printf("%s\n", buff);
closesocket(isockcliid);
system("pause");
return 0;
}
TCP通訊,多客戶端通訊(客戶端 服務端)
客戶端和伺服器間的交流,客戶端傳送資訊,伺服器接收到,並返回資訊 長連線建立socket連線服務端 指定ip位址,埠號 通過ip位址找對應的伺服器 呼叫socket的getinputstream 和getoutputstream 方法獲取和服務端相連的io流 輸入流可以讀取服務端輸出流寫出的資料 輸...
TCP客戶端與服務端通訊
客戶端 include include include include include in.h include include include include define maxline 1024 int main int argc,char ar 建立socketfd socketfd soc...
TCP連線實現 客戶端 服務端 通訊
客戶端 client.c include include include include include include include include define max buf 512 int main int argc,char argv 設定伺服器位址結構體 bzero server ad...