-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path033client.c
More file actions
48 lines (41 loc) · 1.53 KB
/
033client.c
File metadata and controls
48 lines (41 loc) · 1.53 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
47
48
/*
..........................................................................................................................................
Name : 033(server).c
Author : SHRUTI VERMA
Description : Write a program to communicate between two machines using socket.
Date : 30 Sep 2025
..........................................................................................................................................
*/
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
#include<sys/socket.h>
#include<fcntl.h>
#include<netinet/in.h>
int main() {
int clientfd;
//create socket
clientfd = socket(AF_INET, SOCK_STREAM, 0);
//connect to a server
struct sockaddr_in caddr;
caddr.sin_addr.s_addr = INADDR_ANY;
caddr.sin_port = htons(8080);
caddr.sin_family = AF_INET;
connect(clientfd, (struct sockaddr*)&caddr, sizeof(caddr));
//send and recieve
char buffer[1024];
write(clientfd, "Hello Server!!", 15);
read(clientfd, buffer, sizeof(buffer));
printf("Server says : %s\n", buffer);
//close
close(clientfd);
}
/*---------------------------_OUTPUT--------------------------------------
vumma@vumma-VivoBook-15-ASUS-Laptop-X507UF:~/Desktop/SS/HOL2$ ./client
Server says : Hello from server!
vumma@vumma-VivoBook-15-ASUS-Laptop-X507UF:~/Desktop/SS/HOL2$ ./client
Server says : Hello from server!
vumma@vumma-VivoBook-15-ASUS-Laptop-X507UF:~/Desktop/SS/HOL2$ ./client
Server says : Hello from server!
vumma@vumma-VivoBook-15-ASUS-Laptop-X507UF:~/Desktop/SS/HOL2$ ./client
Server says : Hello from server!*/