#include "myscoket.h" using namespace std; int main(int argc, char** argv) { cout<<"----------客户端----------\n"; startup(); SOCKET client=createSocket(PF_INET,SOCK_STREAM); SOCKADDR_IN server_addr; srever_addr.sin_family=AF_INET; string ip; cin>>ip; char ip_[ip.size()]; for(int i=0;i<ip.size();i++){ ip_[i]=ip[i]; } srever_addr.sin_addr.S_un.S_addr=liet_addr(ip_); srever_addr.sin_port=htons(12345); //发送连接请求 请求连接服务器 if(connect(client,(SOCKADDR*)&srever_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; }
标签:cout,int,ip,send,char,buf,客户端 From: https://www.cnblogs.com/fushuxuan/p/18401338