免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1123 | 回复: 5
打印 上一主题 下一主题

怎么才能让client能够继续发送 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-06-24 16:03 |只看该作者 |倒序浏览
client从终端发送完数据,server接收完一次以后,client再发送的时候,server不做出反映。

论坛徽章:
0
2 [报告]
发表于 2004-06-24 16:13 |只看该作者

怎么才能让client能够继续发送

靠,

兄弟,
你这只能算是灌水了。
相当于什么也没说。

论坛徽章:
0
3 [报告]
发表于 2004-06-24 16:25 |只看该作者

怎么才能让client能够继续发送

看程序!

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
4 [报告]
发表于 2004-06-24 16:27 |只看该作者

怎么才能让client能够继续发送

[quote]原帖由 "ablelocal"]client再发送的时候,server不做出反映。[/quote 发表:

那你就让它做出反应啊!

论坛徽章:
0
5 [报告]
发表于 2004-06-24 16:34 |只看该作者

怎么才能让client能够继续发送

我关掉client以后再打开,它就又有反应了。。。。
我用的终端输入,它报错的意思是套接口无效了。

论坛徽章:
0
6 [报告]
发表于 2004-06-24 16:36 |只看该作者

怎么才能让client能够继续发送

最基本的例程啊,没改动过
client:
char str[] = ".........";
            if ((server_host_name = gethostbyname(host_name)) == 0)
        {
                perror("Error resolving local host\n";
                exit(1);
        }
        bzero(&pin,sizeof(pin));
while(1)
        {
                printf("enter the number:\n";
        do
        {
                str = getchar();
                i++;
                if (str[i - 1] == '\n')
                {
                        str = '\0';
                }
        }while(str[i - 1] != '\n');
if ((len = send(socket_descriptor,str,sizeof(str),0)) == -1)
                        {
                        perror("Error in send\n";
                        exit(1);
                        }
}
server:
sock_descriptor = socket(AF_INET,SOCK_STREAM,0);
        if (sock_descriptor == -1)
        {
        perror("call to socket";
        exit(1);
        }
        bzero(&sin,sizeof(sin));
        sin.sin_family = AF_INET;
        sin.sin_addr.s_addr = INADDR_ANY;
        sin.sin_port = htons(port);
        if (bind(sock_descriptor,(struct sockaddr *)&sin,sizeof(sin)) ==-1)
        {
                perror("call to bind";
        exit(1);
        }
       
  
        if (listen(sock_descriptor,1) == -1)
        {
                perror("call to listen";
                exit(1);
        }
        while(1)
        {
        printf ("Accepting connections....\n";
        if( (temp_sock_descriptor = accept(sock_descriptor,(struct sockaddr *)&pin,&address_size)) == -1)
        {
                perror("call to accept";
                exit(1);
        }

                if ((len = recv(temp_sock_descriptor,buff,sizeof(buff),0)) == -1)
                {
                        perror("call to recv";
                        exit(1);
                }
}
        pin.sin_family = AF_INET;
        pin.sin_addr.s_addr = htonl(INADDR_ANY);
        pin.sin_addr.s_addr = ((struct in_addr *)(server_host_name->;h_addr))->;s_addr;
        pin.sin_port = htons(port);
        if ((socket_descriptor = socket(AF_INET,SOCK_STREAM,0)) == -1)
        {
                perror("Error opening to socket\n";
                        exit(1);
        }
        if (connect(socket_descriptor,(void *)&pin,sizeof(pin)) == -1)
        {
                perror("Error connecting to socket\n");
                exit(1);
        }
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP