NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

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

#define PORT 3490
#define MAXSIZE 1024

int main(int argc, char *argv[])
{
struct sockaddr_in server_info;
struct hostent *he;
int socket_fd,num;
char buffer[1024];

char buff[1024];

if (argc != 2) {
fprintf(stderr, "Usage: client hostnamen");
exit(1);
}

if ((he = gethostbyname(argv[1]))==NULL) {
fprintf(stderr, "Cannot get host namen");
exit(1);
}

if ((socket_fd = socket(AF_INET, SOCK_STREAM, 0))== -1) {
fprintf(stderr, "Socket Failure!!n");
exit(1);
}

memset(&server_info, 0, sizeof(server_info));
server_info.sin_family = AF_INET;
server_info.sin_port = htons(PORT);
server_info.sin_addr = *((struct in_addr *)he->h_addr);
if (connect(socket_fd, (struct sockaddr *)&server_info, sizeof(struct sockaddr))<0) {
//fprintf(stderr, "Connection Failuren");
perror("connect");
exit(1);
}

//buffer = "Hello World!! Lets have funn";
//memset(buffer, 0 , sizeof(buffer));
while(1) {
fgets(buffer,MAXSIZE-1,stdin);
if ((send(socket_fd,buffer, strlen(buffer),0))== -1) {
fprintf(stderr, "Failure Sending Messagen");
close(socket_fd);
exit(1);
}
else {
printf("Message being sent: %sn",buffer);
}
}

/*if ((num = recv(socket_fd, buff, 1024,0))== -1) {
//fprintf(stderr,"Error in receiving message!!n");
perror("recv");
exit(1);
}
// num = recv(client_fd, buffer, sizeof(buffer),0);
buff[num] = '';
printf("Message received: %snNumber of bytes received: %dn", buff,num);*/
close(socket_fd);

}

















































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

#define PORT 3490
#define BACKLOG 10

int main()
{
struct sockaddr_in server;
struct sockaddr_in dest;
int status,socket_fd, client_fd,num;
socklen_t size;

char buffer[10241];
char *buff;
// memset(buffer,0,sizeof(buffer));
int yes =1;



if ((socket_fd = socket(AF_INET, SOCK_STREAM, 0))== -1) {
fprintf(stderr, "Socket failure!!n");
exit(1);
}

if (setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1) {
perror("setsockopt");
exit(1);
}
memset(&server, 0, sizeof(server));
memset(&dest,0,sizeof(dest));
server.sin_family = AF_INET;
server.sin_port = htons(PORT);
server.sin_addr.s_addr = INADDR_ANY;
if ((bind(socket_fd, (struct sockaddr *)&server, sizeof(struct sockaddr )))== -1) { //sizeof(struct sockaddr)
fprintf(stderr, "Binding Failuren");
exit(1);
}

if ((listen(socket_fd, BACKLOG))== -1){
fprintf(stderr, "Listening Failuren");
exit(1);
}

while(1) {
size = sizeof(struct sockaddr_in);

if ((client_fd = accept(socket_fd, (struct sockaddr *)&dest, &size))==-1) {
//fprintf(stderr,"Accept Failuren");
perror("accept");
exit(1);
}
printf("Server got connection from client %sn", inet_ntoa(dest.sin_addr));
//buffer = "Hello World!! I am networking!!n";

while(1) {
if ((num = recv(client_fd, buffer, 10240,0))== -1) {
//fprintf(stderr,"Error in receiving message!!n");
perror("recv");
exit(1);
}
else if (num == 0) {
printf("Connection closedn");
return 0;
}
// num = recv(client_fd, buffer, sizeof(buffer),0);
buffer[num] = '';
printf("Message received: %sn", buffer);
}

/* buff = "I am communicating with the client!!n";

if ((send(client_fd,buff, strlen(buff),0))== -1) {
fprintf(stderr, "Failure Sending Messagen");
close(client_fd);
exit(1);
}
else {
printf("Message being sent: %snNumber of bytes sent: %dn",buff, strlen(buff));
}*/

close(client_fd);
close(socket_fd);
//return 0;
}
//close(client_fd);
return 0;
}
     
 
what is notes.io
 

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

     
 
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.