当前位置: 技术问答>linux和unix
socket编程
来源: 互联网 发布时间:2016-08-25
本文导语: server: #include"apue.h" #include #include #include #include #include #include #define BUFLEN 128 #define QLEN 10 #define SERVPORT "4000" #ifndef HOST_NAME_MAX #define HOST_NAME_MAX 256 #endif void serve(int sockfd) { int clfd; FILE *fp; char buf[BUFLEN]; fo...
server:
#include"apue.h"
#include
#include
#include
#include
#include
#include
#define BUFLEN 128
#define QLEN 10
#define SERVPORT "4000"
#ifndef HOST_NAME_MAX
#define HOST_NAME_MAX 256
#endif
void serve(int sockfd)
{
int clfd;
FILE *fp;
char buf[BUFLEN];
for(;;)
{
clfd = accept(sockfd,NULL,NULL);
if (clfd ai_socktype,
aip->ai_protocol);
if (sfd == -1)
continue;
if (bind(sfd, aip->ai_addr, aip->ai_addrlen) == 0){
if (aip->ai_socktype ==SOCK_STREAM||aip->ai_socktype==SOCK_SEQPACKET)
{
if(listen(sfd,QLEN)
#include"apue.h"
#include
#include
#include
#include
#include
#include
#define BUFLEN 128
#define QLEN 10
#define SERVPORT "4000"
#ifndef HOST_NAME_MAX
#define HOST_NAME_MAX 256
#endif
void serve(int sockfd)
{
int clfd;
FILE *fp;
char buf[BUFLEN];
for(;;)
{
clfd = accept(sockfd,NULL,NULL);
if (clfd ai_socktype,
aip->ai_protocol);
if (sfd == -1)
continue;
if (bind(sfd, aip->ai_addr, aip->ai_addrlen) == 0){
if (aip->ai_socktype ==SOCK_STREAM||aip->ai_socktype==SOCK_SEQPACKET)
{
if(listen(sfd,QLEN)