L
loll
Unregistered / Unconfirmed
GUEST, unregistred user!
有一支tcp程序,当在某企业内网时,client呼叫server端可以建立起连接。但是通过外网呼叫server时,无法建立起连接。但是通过外网,可以ping通server,可以telnet到server,但是通过tcp程序,server端根本就收不到connect请求(我用防火墙检测到的)。
到底是网络问题还是程序问题呢?
望兄弟们帮忙
程序如下:
int connect_zxb()
{
struct hostent* h;
struct sockaddr_in sin;
int lable;
if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
{
display(0,"Socket Open Failure!");
set_curr_status(DOWN);
sock=0;
return 0;
}
display(0,"sock ok ...");
if (!(h = gethostbyname("EDCHOST")))
{
display(0,"Can't Find EDCHOST IP ");
set_curr_status(DOWN);
close(sock);
sock=0;
return 0;
}
display(0,"EDCH ok ...");
bzero(&sin, sizeof(sin));
sin.sin_family = AF_INET;
bcopy(h->h_addr, &sin.sin_addr, h->h_length);
if((lable=bind(sock,(struct sockaddr *)&sin,sizeof(sin)))<0)
{
display(0,"Bind error");
set_curr_status(DOWN);
close(sock);
sock=0;
return 0;
}
display(0,"bind ok ...");
if(!(h = gethostbyname("ZHHOST")))
{
display(0,"Can't Find ZHHOST IP");
set_curr_status(DOWN);
close(sock);
sock=0;
return 0;
}
display(0,"ZHHOST ok.");
bzero(&sin,sizeof(sin));
sin.sin_family = AF_INET;
bcopy(h->h_addr, &sin.sin_addr, h->h_length);
sin.sin_port = htons(PORTNUM);
display(0,"connect begin
");
if((lable=connect(sock, (struct sockaddr *)&sin,
sizeof(sin))) < 0)
{
display(0,"Connect failure");
set_curr_status(DOWN);
close(sock);
sock=0;
return 0;
}
display(0,"connect ok");
set_curr_status(UP);
return 1;
}
奇怪的问题是在提示:connect begin
以后,再也没有提示了。既没有“connect faiure”也没有"connect ok"
到底是网络问题还是程序问题呢?
望兄弟们帮忙
程序如下:
int connect_zxb()
{
struct hostent* h;
struct sockaddr_in sin;
int lable;
if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
{
display(0,"Socket Open Failure!");
set_curr_status(DOWN);
sock=0;
return 0;
}
display(0,"sock ok ...");
if (!(h = gethostbyname("EDCHOST")))
{
display(0,"Can't Find EDCHOST IP ");
set_curr_status(DOWN);
close(sock);
sock=0;
return 0;
}
display(0,"EDCH ok ...");
bzero(&sin, sizeof(sin));
sin.sin_family = AF_INET;
bcopy(h->h_addr, &sin.sin_addr, h->h_length);
if((lable=bind(sock,(struct sockaddr *)&sin,sizeof(sin)))<0)
{
display(0,"Bind error");
set_curr_status(DOWN);
close(sock);
sock=0;
return 0;
}
display(0,"bind ok ...");
if(!(h = gethostbyname("ZHHOST")))
{
display(0,"Can't Find ZHHOST IP");
set_curr_status(DOWN);
close(sock);
sock=0;
return 0;
}
display(0,"ZHHOST ok.");
bzero(&sin,sizeof(sin));
sin.sin_family = AF_INET;
bcopy(h->h_addr, &sin.sin_addr, h->h_length);
sin.sin_port = htons(PORTNUM);
display(0,"connect begin
");
if((lable=connect(sock, (struct sockaddr *)&sin,
sizeof(sin))) < 0)
{
display(0,"Connect failure");
set_curr_status(DOWN);
close(sock);
sock=0;
return 0;
}
display(0,"connect ok");
set_curr_status(UP);
return 1;
}
奇怪的问题是在提示:connect begin
以后,再也没有提示了。既没有“connect faiure”也没有"connect ok"