Server side #include <sys/types.h> #include <sys/socket.h> #include <unistd.h> #include
<stdio.h> #include <arpa/inet.h> int main() { //socket int cliFd =
socket(PF_INET, SOCK_STREAM, 0); if(cliFd < 0) { perror("socket error!");
return -1; } printf("socket ok!\n"); //connect struct sockaddr_in servAddr =
{0}; servAddr.sin_family = PF_INET; servAddr.sin_port = htons(8888);
servAddr.sin_addr.s_addr = inet_addr("192.168.31.100"); int ret =
connect(cliFd, (struct sockaddr *)&servAddr, sizeof(servAddr)); if(ret < 0) {
perror("connect error!"); return -1; } printf("connect ok!\n"); //send char
buf[1024] = {0}; printf("please input:"); scanf("%s", buf); send(cliFd, buf,
sizeof(buf), 0); //close close(cliFd); return 0; }
terminal #include <sys/types.h> #include <sys/socket.h> #include <stdio.h> #include
<arpa/inet.h> #include <unistd.h> int main() { //socket int servFd =
socket(PF_INET, SOCK_STREAM, 0); if(servFd < 0) { perror("socket error!");
return -1; } printf("socket ok!\n"); //bind struct sockaddr_in servAddr = {0};
servAddr.sin_family = PF_INET; servAddr.sin_port = htons(8888);
servAddr.sin_addr.s_addr = inet_addr("192.168.31.100"); int ret = bind(servFd,
(struct sockaddr *)&servAddr, sizeof(servAddr)); if(ret < 0) { perror("bind
error!"); return -1; } printf("bind ok!\n"); //listen ret = listen(servFd, 10);
if(ret < 0) { perror("listen error!"); return -1; } printf("listening.....\n");
//accept int connFd = accept(servFd, NULL, NULL); if(connFd < 0) {
perror("accept error!"); return -1; } printf("accept ok!\n"); //recv char
buf[1024] = {0}; ret = recv(connFd, buf, sizeof(buf), 0); if(ret > 0) {
printf("recv form client: %s\n", buf); } //close close(servFd); close(connFd);
return 0; }

Technology
©2019-2020 Toolsou All rights reserved,
html Writing about cherry trees , Writing about cherry trees It's unexpected Python Cherry tree (turtle The gorgeous style of Library ) Browser kernel ( understand )HashMap Explain in detail java Four functional interfaces ( a key , simple )os Simple use of module Some East 14 Pay change 16 salary , Sincerity or routine ?