0% found this document useful (0 votes)
4 views1 page

Client Code

Uploaded by

tanvipal6661
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Client Code

Uploaded by

tanvipal6661
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

File: /home/anshuman/Desktop/cnlab/lab6/client.

c Page 1 of 1

#include<sys/socket.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<stdio.h>
#include<string.h>
#include<unistd.h>
int main(){
//creating socket
int fd ;
fd = socket(AF_INET , SOCK_STREAM, 0);
if(fd == -1){
printf("error");
}
else printf("completed creating socket\n");

struct sockaddr_in server;

server.sin_family = AF_INET;
server.sin_port =htons(5000);
server.sin_addr.s_addr = inet_addr("[Link]");

// to bind the socket

int b = bind(fd ,(struct sockaddr *)&server , sizeof(server));

if(b > -1) printf("bind performed \n");


else printf("error \n");

//connect function

server.sin_family = AF_INET;
server.sin_port =6660;
server.sin_addr.s_addr = inet_addr("[Link]");

connect(fd , (struct sockaddr *)&server , sizeof(server));

//send funtion
char buff[50];
printf("enter a text to send it to the server");

gets(buff);

send(fd , buff , sizeof(buff) , 0);

close(fd);
return 0;
}

You might also like