?? echoclient.cc
字號(hào):
#include <iostream>using namespace std;#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <unistd.h>#include <fcntl.h>#include <cstring>int main(){ cout << "input server IP and port:"; char ip[100]; short port; cin >> ip >> port; sockaddr_in si; si.sin_family = AF_INET; si.sin_port = htons(port); inet_pton(AF_INET,ip,&si.sin_addr); int s = socket(AF_INET,SOCK_STREAM,0); if(s<0){ cout << "error socket!" << endl; return -1; } socklen_t len=sizeof(si); if(connect(s,(sockaddr*)&si,len)<0){ cout << "error connect!" << endl; return -1; } char buf[1000]; for(;;){ int n=read(s,buf,1000); if(n<=0) break; cout << "::" << buf << endl; cout << "input:"; cin.getline(buf, 1000); strcat(buf, "\n"); write(s, buf, strlen(buf)); if(buf[0]=='q') break; } close(s);}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -