use ggg
This commit is contained in:
parent
61366a07b6
commit
237fea4f51
13
client.c
13
client.c
@ -79,6 +79,19 @@ int main(int argc , char ** argv)
|
||||
perror("fputs error");
|
||||
exit(1);
|
||||
}//if
|
||||
|
||||
if(readline(sockfd , recvline , MAX_LINE) == 0)
|
||||
{
|
||||
perror("server terminated prematurely");
|
||||
exit(1);
|
||||
}//if
|
||||
|
||||
if(fputs(recvline , stdout) == EOF)
|
||||
{
|
||||
perror("fputs error");
|
||||
exit(1);
|
||||
}//if
|
||||
|
||||
}//while
|
||||
|
||||
/*(5) 关闭套接字*/
|
||||
|
5
def.h
Normal file
5
def.h
Normal file
@ -0,0 +1,5 @@
|
||||
int sockfd;
|
||||
int sockad;
|
||||
char *s;
|
||||
struct sockaddr_in seraddr;
|
||||
struct sockaddr_in cliaddr;
|
17
inclu.h
17
inclu.h
@ -1,16 +1,5 @@
|
||||
#include "def.h"
|
||||
#include <stdio.h>
|
||||
//#include <stdlib.h>
|
||||
//#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/socket.h>
|
||||
//#include <sys/types.h>
|
||||
//#include <unistd.h>
|
||||
//#include <errno.h>
|
||||
//#include <netinet/in.h>
|
||||
//#include <netdb.h>
|
||||
//#include <arpa/inet.h>
|
||||
//
|
||||
//const int MAX_LINE = 2048;
|
||||
const int PORT = 6000;
|
||||
const int BACKLOG = 10;
|
||||
const int LISTENQ = 6666;
|
||||
const int MAX_CONNECT = 20;
|
||||
#include <netinet/in.h>
|
||||
|
16
s.c
Normal file
16
s.c
Normal file
@ -0,0 +1,16 @@
|
||||
#include
|
||||
int main(int argc,char **argv)
|
||||
{
|
||||
sockfd = socket(AF_INET,SOCK_STREAM,0);
|
||||
bzero(&seraddr,sizeof(seraddr));
|
||||
seraddr.sin_family = AF_INET;
|
||||
seraddr.sin_port = htons(800);
|
||||
seraddr.sin_addr.s_addr = inet_addr("127.0.0.1");
|
||||
bind(sockfd,(struct sockaddr *)&seraddr,sizeof(struct sockaddr);
|
||||
listen(sockfd, 5);
|
||||
accept(sockad, NULL, NULL);
|
||||
send(sockad,s , sizeof(char), 0);
|
||||
//recv(sockad, const void *buf, size_t nbytes, int flags);
|
||||
|
||||
return 0;
|
||||
}
|
3
server.c
3
server.c
@ -2,6 +2,7 @@
|
||||
|
||||
int main(int argc , char **argv)
|
||||
{
|
||||
char second[]="second";
|
||||
/*声明服务器地址和客户链接地址*/
|
||||
struct sockaddr_in servaddr , cliaddr;
|
||||
|
||||
@ -62,6 +63,8 @@ int main(int argc , char **argv)
|
||||
while((n = read(connfd , buff , MAX_LINE)) > 0)
|
||||
{
|
||||
write(connfd , buff , n);
|
||||
write(connfd , second , 6);
|
||||
|
||||
}
|
||||
exit(0);
|
||||
}//if
|
||||
|
Loading…
Reference in New Issue
Block a user