当前位置: 技术问答>linux和unix
我只会用循环解决多客户,如何用FORK语句实现啊
来源: 互联网 发布时间:2016-04-06
本文导语: 服务端的 #include #include #include "inet.h" struct sockaddr_in sin; int fromlen; struct hostent *hp; int initserver(int port) { int s,new_socket; hp=gethostbyname("F80_test"); if(hp==NULL) { perror(" host address error"); exit(2); } s=socket(AF_...
服务端的
#include
#include
#include "inet.h"
struct sockaddr_in sin;
int fromlen;
struct hostent *hp;
int initserver(int port)
{
int s,new_socket;
hp=gethostbyname("F80_test");
if(hp==NULL)
{
perror(" host address error");
exit(2);
}
s=socket(AF_INET,SOCK_STREAM,0);
if(sh_addr,&sin.sin_addr,hp->h_length);
if(bind(s,&sin,sizeof(sin)) b) themax = a;
else themax = b;
return themax;
}
void set_name( char *line, char *name)
{
strcpy( name, &line[1]);
sprintf( line, "%s is comingn", name);
}
void add_name( char *line, char *name)
{
char theline[MAX_LINE];
strcpy( theline, name);
strcat( theline, " : ");
strcat( theline, line);
strcpy( line, theline);
}
int user_free( int user_link[MAX_CLIENT])
{
int i = 0;
while ( ( user_link[i] != 0)&&( i
#include
#include
#include "inet.h"
struct sockaddr_in sin;
int fromlen;
struct hostent *hp;
int initserver(int port)
{
int s,new_socket;
hp=gethostbyname("F80_test");
if(hp==NULL)
{
perror(" host address error");
exit(2);
}
s=socket(AF_INET,SOCK_STREAM,0);
if(sh_addr,&sin.sin_addr,hp->h_length);
if(bind(s,&sin,sizeof(sin)) b) themax = a;
else themax = b;
return themax;
}
void set_name( char *line, char *name)
{
strcpy( name, &line[1]);
sprintf( line, "%s is comingn", name);
}
void add_name( char *line, char *name)
{
char theline[MAX_LINE];
strcpy( theline, name);
strcat( theline, " : ");
strcat( theline, line);
strcpy( line, theline);
}
int user_free( int user_link[MAX_CLIENT])
{
int i = 0;
while ( ( user_link[i] != 0)&&( i