//客户端 #include "mysocket.h"//头文件 using namespace std; int main(){ cout<<"--------------------客户端-------------------\n"; startup(); //启动 //检测版本号 if(LOBYTE(wsdata.wVersion)!=2 || HIBYTE(wsdata.wHighVersion)!=2) { cout << "版本号与服务端不匹配!" << endl; WSACleanup(); return FALSE; } //填充服务端信息:这里填和服务端一样的就好,不做解释 SOCKET client = createSocket(PF_INET,SOCK_STREAM); SOCKADDR_IN server_addr; server_addr.sin_family = AF_INET; server_addr.sin_addr.S_un.S_addr = inet_addr("192.168.1.48"); server_addr.sin_port = htons(8226); //发送连接请求 请求连接服务器 if (connect(client, (SOCKADDR*)&server_addr, sizeof(SOCKADDR))==SOCKET_ERROR) { cout << "连接错误!" << endl; WSACleanup(); return -1; } cout << "成功连接到服务器" << endl; char send_buf[1145], recv_buf[4514]; while(1){ cout << "输入要发送的信息:"; cin >> send_buf; mysend(client, send_buf); cout << "等待服务端响应...\n"; myrecv(client, recv_buf); cout << "收到来自服务端的信息:" << recv_buf << endl; } return 0; }
标签:std,cout,send,main,buf,客户端 From: https://www.cnblogs.com/wangyihang-xh/p/18238349