-
Notifications
You must be signed in to change notification settings - Fork 1
/
client3.c
44 lines (31 loc) · 787 Bytes
/
client3.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
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
int main()
{
char request[256] = "Hello I am Client are you there";
char buf[200];
// create the socket
int sock;
sock = socket(AF_INET, SOCK_STREAM, 0);
//setup an address
struct sockaddr_in server_address;
server_address.sin_family = AF_INET;
server_address.sin_addr.s_addr = INADDR_ANY;
server_address.sin_port = htons(3001);
connect(sock, (struct sockaddr *) &server_address, sizeof(server_address));
char st1[30]="exit";
do
{
printf("enter message ");
scanf("%s",&request);
send(sock, request, sizeof(request), 0);
recv(sock, &buf, sizeof(buf), 0);
printf("%s",&buf);
}
while(strcmp(request,st1));
close(sock);
return 0;
}