标题:connect无法连接
只看楼主
酷儿
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2007-10-15
 问题点数:0 回复次数:1 
connect无法连接
我写了一个客户端,如下
#include<PROCESS.H>
#include<windows.h>
#include<winsock.h>
#include<sys/types.h>
#include<fcntl.h>
#include<wsipx.h>
#include<stdio.h>
#include<iostream.h>

#define SERV_TCP_PORT 600

int main()
{
    int sockfd,a;
    int nRet;
    char szBuf[1024];
    struct sockaddr_in serv_addr;
    WORD wVersionRequested=MAKEWORD(1,1);
    WSADATA wsaData;

    if(WSAStartup(wVersionRequested,&wsaData)){
        printf("WSAStartup failed %s\n", WSAGetLastError());
        return -1;
    }
    if((sockfd=socket(AF_INET,SOCK_STREAM,0))<0){
        printf("server:can't open stream socker\n");
    }
    else     printf("sockfd=%d\n",sockfd);

    memset((char *)&serv_addr,0,sizeof(struct sockaddr_in));
    serv_addr.sin_family=AF_INET;
    serv_addr.sin_addr.S_un.S_addr=htonl(inet_addr("192.168.0.96"));
    serv_addr.sin_port=htons(400);


    if((a=connect(sockfd,(struct sockaddr *)&serv_addr,sizeof(struct sockaddr*)))==0)
        printf("the connect is success");
    else {
        printf("a=%d\n",a);
    return -1;
    }

但是无法连接上,请问什么原因??
搜索更多相关主题的帖子: connect 
2008-05-10 13:04
余来
Rank: 6Rank: 6
等 级:贵宾
威 望:26
帖 子:956
专家分:18
注 册:2006-8-13
得分:0 
代码如果没错的话就是对方放火墙或者自己电脑是的放火强过滤了

2008-05-10 14:47



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-213499-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.143991 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved