找回密码
 立即注册
查看: 112|回复: 2

娈电缃灏炕璇涓搴

[复制链接]

1964

主题

0

回帖

1964

积分

金牌会员

积分
1964
发表于 2023-8-26 21:46:32 | 显示全部楼层 |阅读模式
  1. // 鍐欎竴娈电敤缃戠粶灏嗚嫳鏂囩炕璇戞垚涓枃鐨勭▼搴#include <stdio.h>#include <string.h>#include <stdlib.h>#include <unistd.h>#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <netdb.h>#include <errno.h>#include <fcntl.h>#include <sys/stat.h>int main(int argc, char *argv[]){    int sockfd;    struct sockaddr_in servaddr;    char buf[1024];    int n;    if (argc != 2)    {        printf("usage: tcpclient <IPaddress>\n");        exit(1);    }    sockfd = socket(AF_INET, SOCK_STREAM, 0);    bzero(&servaddr, sizeof(servaddr));    servaddr.sin_family = AF_INET;    servaddr.sin_port = htons(12345);    inet_pton(AF_INET, argv[1], &servaddr.sin_addr);    connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr));    while (1)    {        printf("Please enter the message:");        fgets(buf, 1024, stdin);        write(sockfd, buf, strlen(buf));        n = read(sockfd, buf, 1024);        if (n == 0)        {            printf("The other side has been closed.\n");            break;        }        else        {            printf("The message from server is:\n");            write(STDOUT_FILENO, buf, n);        }    }    close(sockfd);    return 0;}
复制代码
回复

使用道具 举报

0

主题

1012

回帖

0

积分

新手上路

积分
0
发表于 2023-8-26 21:49:32 | 显示全部楼层
濡備綍杩愯姝や唬鐮
回复 支持 反对

使用道具 举报

0

主题

981

回帖

0

积分

新手上路

积分
0
发表于 2023-8-26 21:50:28 | 显示全部楼层
鍦╲scode缂栬瘧鍗冲彲.
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|翻墙党

GMT+8, 2026-10-2 18:49 , Processed in 0.057925 second(s), 23 queries .

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表