NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<netinet/ip.h>
#include<arpa/inet.h>
#include<string.h>
#include<ctype.h>

int find_gcd(int a, int b)
{
if (a == 0)
return b;
return find_gcd(b % a, a);
}

int main(){
int sockfd,len,line;
char buff[50];
char *res_msg;
int num[2];
struct sockaddr_in addrport,src_addr,dest_addr;
sockfd = socket(AF_INET,SOCK_DGRAM,0);
if(sockfd == -1){
printf("Socket creation failed!!n");
exit(0);
}
else{
printf("Socket Created!!n");
}
addrport.sin_family=AF_INET;
addrport.sin_port=htons(4040);
addrport.sin_addr.s_addr=inet_addr("127.0.0.1");
len = sizeof(src_addr);
line = 50;
if(bind(sockfd,(struct sockaddr *)&addrport,sizeof(addrport))!=-1){
printf("Bind Complete.n");
int res_1 = recvfrom(sockfd,&num,line,0,(struct sockaddr*)&src_addr,&len);
//int res_2 = recvfrom(sockfd,num2,line,0,(struct sockaddr*)&src_addr,&len);
if(res_1 == -1){
printf("Receive Error!n");
}
else{
//buff[r]='';
printf("The two numbers Received from the client are %d and %dn",num[0],num[1]);
}
dest_addr.sin_family=AF_INET;
dest_addr.sin_port=htons(5100);
dest_addr.sin_addr.s_addr=inet_addr("127.0.0.1");
int ans = find_gcd(num[0],num[1]);
int s = sendto(sockfd,&ans,sizeof(ans),0,(struct sockaddr*)&dest_addr,sizeof(dest_addr));
if(s==-1){
printf("Error in sending the message!n");
exit(0);
}
else{
printf("Response message sent successfully!n");
printf("The GCD of the two numbers is :- %dn",ans);
}
}
else{
printf("Bind Incomplete!n");
}
return 0;
}



#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<netinet/ip.h>
#include<arpa/inet.h>
#include<string.h>


int main(){
int sockfd;
char str[50],buff[50];
int num[2],ans = 0;
struct sockaddr_in addrport,dest_addr,src_addr;
sockfd = socket(AF_INET,SOCK_DGRAM,0);
if(sockfd == -1){
printf("Client Socket creation failed!!n");
exit(0);
}
else{
printf("Client Socket Created!!n");
}
addrport.sin_family=AF_INET;
addrport.sin_port=htons(5100);
addrport.sin_addr.s_addr=inet_addr("127.0.0.1");
if(bind(sockfd,(struct sockaddr *)&addrport,sizeof(addrport))!=-1){
printf("Client Bind completed!n");
printf("Enter the two numbers :- ");
scanf("%d%d",&num[0],&num[1]);
dest_addr.sin_family=AF_INET;
dest_addr.sin_port=htons(4040);
dest_addr.sin_addr.s_addr=inet_addr("127.0.0.1");
int s1 = sendto(sockfd,&num,sizeof(num),0,(struct sockaddr*)&dest_addr,sizeof(dest_addr));
//int s2 = sendto(sockfd,num2,sizeof(num2),0,(struct sockaddr*)&dest_addr,sizeof(dest_addr));
if(s1 ==-1){
printf("Error in sending the message!n");
exit(0);
}
else{
printf("Client message sent successfully!n");
}
int len = sizeof(src_addr);
int line = 50;
int r = recvfrom(sockfd,&ans,line,0,(struct sockaddr*)&src_addr,&len);
if(r == -1){
printf("Receive Error!");
}
else{
printf("Message Received from server :- n%dn",ans);
}
}
else{
printf("Bind Incomplete!n");
}
return 0;
}



     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.