-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcliant.c
More file actions
46 lines (40 loc) · 1.13 KB
/
cliant.c
File metadata and controls
46 lines (40 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using namespace std;
#include<iostream>
#include<arpa/inet.h>
#include<sys/socket.h>
#include<string.h>
#include<unistd.h>
#include<cstdio>
void commun(int sock){
char message[500]="test test";
char buf[256];
send(sock,message,strlen(message),0);
//送信完了
int len_r=recv(sock,buf,256,0);
buf[len_r]='\0';
cout<<buf<<endl;
//受信完了
//printf("%s\n",buf);
}
int main(int argc,char ** argv){
int sock=socket(PF_INET,SOCK_STREAM,0);
struct sockaddr_in target;
target.sin_family=AF_INET;
target.sin_addr.s_addr=inet_addr("10.13.64.20");
target.sin_port=htons(10001);
//サーバーの構造体を作成している
connect(sock,(struct sockaddr*)&target,sizeof(target));
commun(sock);
//cout<<sock<<endl;
close(sock);
//bind(terget,(struct terget*)&terget,sizeof(terget));
//listen(terget,5);
return 0;
}//g++ cliant.c -o cliant.exe
// ./cliant.exe
//\\file01.edu-kct.local\home\k16013wi\desktop\ネットワークぷろぐらみんぐ
/*
終了ステータスとして1,-1
ポートは何番が使えるか
終了ステータスとして負の値はどうなるか
*/