当前位置: 技术问答>linux和unix
socket编程的问题(初学者问)
来源: 互联网 发布时间:2016-08-25
本文导语: 是一个C/S程序运行后显示could not connect 请帮忙解决! 下面是代码: server: #include"apue.h" #include #include #include #include #include #include #define QLEN 10 #define SERVPORT "4000" #ifndef HOST_NAME_MAX #define HOST_NAME_MAX 256 #endif int in...
是一个C/S程序运行后显示could not connect 请帮忙解决!
下面是代码:
server:
#include"apue.h"
#include
#include
#include
#include
#include
#include
#define QLEN 10
#define SERVPORT "4000"
#ifndef HOST_NAME_MAX
#define HOST_NAME_MAX 256
#endif
int initserver(int type,const struct sockaddr *addr,socklen_t alen,int qlen)
{
int fd;
int err=0;
if ((fd=socket(addr->sa_family,type,0))ai_socktype ==SOCK_STREAM||aip->ai_socktype==SOCK_SEQPACKET)
{
if(listen(sfd,QLEN)ai_addr, aip->ai_addrlen) != -1)
break; /* Success */
close(sfd);
}
if (aip == NULL) { /* No address succeeded */
fprintf(stderr, "Could not connectn");
exit(EXIT_FAILURE);
}
freeaddrinfo(ailist); /* No longer needed */
print_uptime(sfd);
exit(0);
}
下面是代码:
server:
#include"apue.h"
#include
#include
#include
#include
#include
#include
#define QLEN 10
#define SERVPORT "4000"
#ifndef HOST_NAME_MAX
#define HOST_NAME_MAX 256
#endif
int initserver(int type,const struct sockaddr *addr,socklen_t alen,int qlen)
{
int fd;
int err=0;
if ((fd=socket(addr->sa_family,type,0))ai_socktype ==SOCK_STREAM||aip->ai_socktype==SOCK_SEQPACKET)
{
if(listen(sfd,QLEN)ai_addr, aip->ai_addrlen) != -1)
break; /* Success */
close(sfd);
}
if (aip == NULL) { /* No address succeeded */
fprintf(stderr, "Could not connectn");
exit(EXIT_FAILURE);
}
freeaddrinfo(ailist); /* No longer needed */
print_uptime(sfd);
exit(0);
}
|
服务器运行起来没有?
服务器对应的进程有无启动?
IP指定正确嘛?
服务器对应的进程有无启动?
IP指定正确嘛?
|
如果硬件配置保证无误
就看看 syslog
就看看 syslog
|
/var/log/.. 看看