客户端
#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <string.h>
#define SERVPORT 5000
int main(int argc,char ** argv)
{
int sockfd,n;
struct sockaddr_in servaddr,cliaddr;
char sendline[1000];//发送缓冲区大小
char recvline[1000];
if(argc != 2)
{
printf("usage:server address!\n");
exit(0);
}
sockfd = socket(AF_INET,SOCK_STREAM,0);
bzero(&servaddr,sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(SERVPORT);
servaddr.sin_addr.s_addr = inet_addr(argv[1]);
connect(sockfd,(struct sockaddr *)&servaddr,sizeof(servaddr));
while(fgets(sendline,1000,stdin) != NULL)
{
sendto(sockfd,sendline,strlen(sendline),0,
(struct sockaddr *)&servaddr,sizeof(servaddr));
n = recvfrom(sockfd,rec