Linux?????socket??????
???????????? ???????[ 2015/6/16 11:31:27 ] ?????????????? socket
??????????????????????????????UNIX?????????????????????????????????????????????????????е??????????????????????????????????????????????д??????д??????????е????100?????????????????????????????????????????????飬???????????????????????????????????κ?????顢??????????Ρ?
??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????Щ?????????????cvmimi_linhai@foxmail.com????????????????
????????????????????????????
????--> 1?????????????????
????--> 2???????????????????????????????????????????Ρ?
????--> 3???????????????????TCP????????????齻??
????--> 4??IPv4??IPv6??????????
????--> 5???Щ???????????
????--> 6??????????
????client.c
1 #include <stdio.h>
2 #include <sys/socket.h>
3 #include <sys/types.h>
4 #include <stdlib.h>
5 #include <netinet/in.h>
6 #include <errno.h>
7 #include <string.h>
8 #include <arpa/inet.h>
9 #include <unistd.h>
10 #define MAXLINE 1024
11 int main(int argc??char **argv)
12 {
13 char *servInetAddr = "127.0.0.1";
14 int socketfd;
15 struct sockaddr_in sockaddr;
16 char recvline[MAXLINE]?? sendline[MAXLINE];
17 int n;
18
19 if(argc != 2)
20 {
21 printf("client <ipaddress>
");
22 exit(0);
23 }
24
25 socketfd = socket(AF_INET??SOCK_STREAM??0);
26 memset(&sockaddr??0??sizeof(sockaddr));
27 sockaddr.sin_family = AF_INET;
28 sockaddr.sin_port = htons(10004);
29 inet_pton(AF_INET??servInetAddr??&sockaddr.sin_addr)
30 if((connect(socketfd??(struct sockaddr*)&sockaddr??sizeof(sockaddr))) < 0 )
31 {
31 printf("connect error %s errno: %d
"??strerror(errno)??errno);
32 exit(0);
33 }
34
35 printf("send message to server
");
36
37 fgets(sendline??1024??stdin);
38
39 if((send(socketfd??sendline??strlen(sendline)??0)) < 0)
40 {
41 printf("send mes error: %s errno : %d"??strerror(errno)??errno);
42 exit(0);
43 }
44
45 close(socketfd);
46 printf("exit
");
47 exit(0);
48 }
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11