udp tcp epoll serv
[socket_samples.git] / tcp_cli.c
blob91ea5bb4280c36355b1da2dcf28f4e6d803a75f5
1 #include <stdio.h>
2 #include <sys/socket.h>
3 #include <sys/epoll.h>
4 #include <netinet/in.h>
5 #include <arpa/inet.h>
6 #include <fcntl.h>
7 #include <unistd.h>
8 #include <errno.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <errno.h>
13 int main(){
14 int fd;
15 struct sockaddr_in clientaddr;
16 char recvline[1000] = "abcdef";
17 int n = 0;
18 if((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
19 perror("socket create error");
21 bzero(&clientaddr, sizeof(clientaddr));
22 clientaddr.sin_family = AF_INET;
23 inet_aton("127.0.0.1",&(clientaddr.sin_addr));
24 clientaddr.sin_port = htons(1235);
26 if(connect(fd, (struct sockaddr *)&clientaddr,sizeof(clientaddr)) < 0)
27 perror("connect error");
28 printf("%d\n",fd);
29 while((n = write(fd, recvline,6))>0){
30 printf("recvline = %s",recvline);
31 if(n > 0)
32 break;
34 if (n < 0)
35 perror("write error");
37 exit(0);