+ -
当前位置:首页 → 问答吧 → [分享] Linux下用Anjuta写个Hello World 的C++程序竟如此简单!

[分享] Linux下用Anjuta写个Hello World 的C++程序竟如此简单!

时间:2010-10-17

来源:互联网

代码:
/* TCP Socket functions; */
int tcp_init()
{
   return socket(PF_INET,SOCK_STREAM,0);
}

int tcp_connect(int st,ATBD* info)
{
   struct sockaddr_in sa;
   sa.sin_family=AF_INET;
   sa.sin_port=htons(info->at_port);
   sa.sin_addr.s_addr=inet_addr(info->at_address);
   if(connect(st,(struct sockaddr*)&sa,sizeof(struct sockaddr_in))<0)
   {
      pmlog(strerror(errno));
      return -1;
   }
   return 0;
}
/* The struct below is used to authorization; */
typedef struct _auth_bundle
{
   char at_hostname[128];   /* The server's hostname; */
   char at_address[16];   /* The server's IP address; */
   int  at_port;   /* The number of port which is used to communication; */
   char at_username[64]; /* Username; */
   char at_password[64]; /* Password; */
   char at_username_base64[96];   /* Username, after base64; */
   char at_password_base64[96];   /* Password, after base64; */
} ATBD;

每次connect都超时。但是不封装能够连接上。请问如何解决?

作者: leycn   发布时间: 2010-10-17

代码:
/* TCP Socket functions; */
int tcp_init()
{
   return socket(PF_INET,SOCK_STREAM,0);
}

int tcp_connect(int st,ATBD* info)
{
   struct sockaddr_in sa;
   sa.sin_family=AF_INET;
   sa.sin_port=htons(info->at_port);
   sa.sin_addr.s_addr=inet_addr(info->at_address);
   if(connect(st,(struct sockaddr*)&sa,sizeof(struct sockaddr_in))<0)
   {
      pmlog(strerror(errno));
      return -1;
   }
   return 0;
}
/* The struct below is used to authorization; */
typedef struct _auth_bundle
{
   char at_hostname[128];   /* The server's hostname; */
   char at_address[16];   /* The server's IP address; */
   int  at_port;   /* The number of port which is used to communication; */
   char at_username[64]; /* Username; */
   char at_password[64]; /* Password; */
   char at_username_base64[96];   /* Username, after base64; */
   char at_password_base64[96];   /* Password, after base64; */
} ATBD;

每次connect都超时。但是不封装能够连接上。请问如何解决?

作者: leycn   发布时间: 2010-10-17

代码:
/* TCP Socket functions; */
int tcp_init()
{
   return socket(PF_INET,SOCK_STREAM,0);
}

int tcp_connect(int st,ATBD* info)
{
   struct sockaddr_in sa;
   sa.sin_family=AF_INET;
   sa.sin_port=htons(info->at_port);
   sa.sin_addr.s_addr=inet_addr(info->at_address);
   if(connect(st,(struct sockaddr*)&sa,sizeof(struct sockaddr_in))<0)
   {
      pmlog(strerror(errno));
      return -1;
   }
   return 0;
}
/* The struct below is used to authorization; */
typedef struct _auth_bundle
{
   char at_hostname[128];   /* The server's hostname; */
   char at_address[16];   /* The server's IP address; */
   int  at_port;   /* The number of port which is used to communication; */
   char at_username[64]; /* Username; */
   char at_password[64]; /* Password; */
   char at_username_base64[96];   /* Username, after base64; */
   char at_password_base64[96];   /* Password, after base64; */
} ATBD;

每次connect都超时。但是不封装能够连接上。请问如何解决?

作者: leycn   发布时间: 2010-10-17