Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
#include<stdio.h>
#include<stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>
int main(){
int sockfd;
struct sockaddr_in server,client;
sockfd=socket(AF_INET,SOCK_DGRAM,0);
if(sockfd==-1)
{
printf("Socket not createdn");
exit(0);
}
else
{
printf("Socket Createdn");
}
server.sin_family=AF_INET;
server.sin_port=htons(3050);
server.sin_addr.s_addr=INADDR_ANY;
// inet_addr("127.0.0.1")
// ipconfig in terminal to find your ip address
int x= bind(sockfd,(struct sockaddr *)&server,sizeof(server));
if(x==-1){
printf("Bind Failuren");
exit(0);
}
else
{
printf("Bind Successfuln");
}
int a,b,lcm;
int s=sizeof(client);
recvfrom(sockfd,&a,100,0,(struct sockaddr *)&client,&s);
printf("Recieved message is %dn",a);
recvfrom(sockfd,&b,100,0,(struct sockaddr *)&client,&s);
printf("Recieved message is %dn",b);
int max_Value = (a>b)?a:b;
while(1)
{
if(max_Value % a== 0 && max_Value %b == 0)
{
lcm=max_Value;
break;
}
++max_Value;
}
printf("lcm is %dn",lcm);
sendto(sockfd,&lcm,4,0,(struct sockaddr *)&client,sizeof(client));
close(sockfd);
return 0;
}
CLIENT
#include<stdio.h>
#include<stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>
int main(){
int sockfd;
struct sockaddr_in server;
sockfd=socket(AF_INET,SOCK_DGRAM,0);
if(sockfd==-1)
{
printf("Socket not createdn");
exit(0);
}
else
{
printf("Socket Createdn");
}
server.sin_family=AF_INET;
server.sin_port=htons(3050);
server.sin_addr.s_addr=INADDR_ANY;
int a,b;
printf("nEnter first number = ");
scanf("%d",&a);
sendto(sockfd,&a,4,0,(struct sockaddr *)&server,sizeof(server));
printf("nEnter second number = ");
scanf("%d",&b);
sendto(sockfd,&b,4,0,(struct sockaddr *)&server,sizeof(server));
int rec;
int s=sizeof(server);
recvfrom(sockfd,&rec,4,0,(struct sockaddr *)&server,&s);
printf("Recieved message lcm is %dn",rec);
close(sockfd);
return 0;
}
SERVER
#include<stdio.h>
#include<stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>
int main(){
int sockfd;
struct sockaddr_in server,client;
sockfd=socket(AF_INET,SOCK_DGRAM,0);
if(sockfd==-1)
{
printf("Socket not createdn");
exit(0);
}
else
{
printf("Socket Createdn");
}
server.sin_family=AF_INET;
server.sin_port=htons(3050);
server.sin_addr.s_addr=INADDR_ANY;
// inet_addr("127.0.0.1")
// ipconfig in terminal to find your ip address
int x= bind(sockfd,(struct sockaddr *)&server,sizeof(server));
if(x==-1){
printf("Bind Failuren");
exit(0);
}
else
{
printf("Bind Successfuln");
}
int a,n;
int s=sizeof(client);
recvfrom(sockfd,&a,100,0,(struct sockaddr *)&client,&s);
printf("Recieved message is %dn",a);
while(a!=0)
{
int d=a%10;
if(d%2==0)
n=n*10+d;
a=a/10;
}
sendto(sockfd,&n,4,0,(struct sockaddr *)&client,sizeof(client));
close(sockfd);
return 0;
}
CLIENT
#include<stdio.h>
#include<stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>
int main(){
int sockfd;
struct sockaddr_in server;
sockfd=socket(AF_INET,SOCK_DGRAM,0);
if(sockfd==-1)
{
printf("Socket not createdn");
exit(0);
}
else
{
printf("Socket Createdn");
}
server.sin_family=AF_INET;
server.sin_port=htons(3050);
server.sin_addr.s_addr=INADDR_ANY;
int a,b;
printf("nEnter first number = ");
scanf("%d",&a);
sendto(sockfd,&a,4,0,(struct sockaddr *)&server,sizeof(server));
int rec;
int s=sizeof(server);
recvfrom(sockfd,&rec,4,0,(struct sockaddr *)&server,&s);
printf("Recieved message his %dn",rec);
close(sockfd);
return 0;
}
![]() |
Notes is a web-based application for online 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 14 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