QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1746|回复: 2

socket程序出错,帮忙看看

[复制链接]
发表于 2008-3-18 10:09:06 | 显示全部楼层 |阅读模式
#include <sys/socket.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <netdb.h>
#include <netinet/in.h>
#include <string.h>

#define IP "192.168.1.1"

int main(int ac,char* av){
int s,cnt,port=0;
struct sockaddr_in addr;

s=socket(PF_INET,SOCK_STREAM,0);
if(s==-1){printf("sock err!");_exit(1);};

printf("input port number:");

scanf("%d",&port);
printf("test!");

addr.sin_family=AF_INET;
addr.sin_port=htons(port);
addr.sin_addr.s_addr=inet_addr(IP);
printf("test!");
cnt=connect(s,(struct sockaddr *)&addr,sizeof addr);

if(cnt==-1){printf("connetc err!");_exit(1);}
else{
printf("\nport %d open!",port);
}

close(s);
return 0;
}

结果是:
debian:/program#./shiy
input port number:21
debian:/program#
发表于 2008-3-18 17:21:39 | 显示全部楼层
你printf 里没得换行  所以缓冲没有满的时候就不会打印
回复

使用道具 举报

发表于 2008-3-18 17:21:57 | 显示全部楼层
加了就OK
回复

使用道具 举报

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

本版积分规则

GMT+8, 2024-4-23 17:27 , Processed in 0.096497 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

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