-
Notifications
You must be signed in to change notification settings - Fork 1
/
client1.c
70 lines (56 loc) · 1.47 KB
/
client1.c
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include<stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <string.h>
#include <netinet/in.h>
#include <arpa/inet.h>
int main(int argc , char *argv[])
{
int sock;
struct sockaddr_in server_addr;
char msg[2000],server_msg[2000]="";
sock = socket(AF_INET , SOCK_STREAM , 0); //create socket
if (sock == -1)
{
printf("could not create socket");
}
printf("Socket created");
server_addr.sin_addr.s_addr = inet_addr("130.65.25.1");
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(atoi(argv[1]));
//Connect to remote server_addr TCP
if (connect(sock , (struct sockaddr *)&server_addr , sizeof(server_addr)) < 0)
{
printf("connection error");
return 1;
}
printf("Connected to server :) \n");
//Server Reply
while(1)
{
printf("write your hostname : ");
scanf("%s",msg);
if (send(sock,msg, 2000 , 0) < 0)
{
printf("send error");
return 1;
}
//strcpy(server_msg,NULL);
if(recv(sock , server_msg , 2000 , 0) < 0)
{
printf("recv failed");
break;
}
printf("Reply From Server : %s \n ",server_msg);
//strcpy(server_msg,NULL);
//strcpy(, "");
// server_msg[0] = '\0';
//set response null
int j;
for (j = 0; j < 100; j++) {
server_msg[j] = '\0';
}
}
return 0;
}