NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>


int main(int argc, char *argv[]) {
// port to start the server on
int SERVER_PORT = 3700;
socklen_t client_address_len;

// socket address used for the server
struct sockaddr_in server_address;
memset(&server_address, 0, sizeof(server_address));

//Setting different required variables....
server_address.sin_family = AF_INET;
server_address.sin_port = htons(SERVER_PORT);
server_address.sin_addr.s_addr = htonl(INADDR_ANY);

//creating a TCP socket, creation returns -1 on failure
int listen_sock;
if ((listen_sock = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
printf("could not create listen socketn");
return 1;
}

//Binding the socket,, which is usually considered as second step in socket programming
if ((bind(listen_sock, (struct sockaddr *)&server_address,
sizeof(server_address))) < 0) {
printf("could not bind socketn");
return 1;
}

// This is maximum number of clients that can connect to this server through this socket
//listen() returns -1 on error
int wait_size = 16;
if (listen(listen_sock, wait_size) < 0) {
printf("could not open socket for listeningn");
return 1;
}

// socket address used to store client address
struct sockaddr_in client_address;


//Run indefinitely to continue listening for clients ...
while (true) {
// open a new socket to transmit data per connection
int sock;
if ((sock = accept(listen_sock, (struct sockaddr *)&client_address, &client_address_len)) < 0) {
printf("could not open a socket to accept datan");
return 1;
}

int n = 0;
int len = 0, maxlen = 100;
char buffer[maxlen];
char *pbuffer = buffer;
char command_to_run[20] = " ";
char add_str[15] = " >logFile.txt";
printf("client connected with ip address: %sn",
inet_ntoa(client_address.sin_addr));

// keep running as long as the client keeps the connection open
while ((n = recv(sock, pbuffer, maxlen, 0)) > 0) {
pbuffer += n;
maxlen -= n;
len += n;

printf("Server received: '%s'n", buffer);
strcat(command_to_run, buffer);
strcat(command_to_run, add_str);
printf("%s",command_to_run);
system(command_to_run);

// echo received content back

/* Open the command for reading. */
char command[10];
int x=0;
for(x=0; x<10; x++){
command[x] = buffer[x];
}

FILE *fp;
char str[1000];
char* filename = "logFile.txt";

fp = fopen(filename, "r");
if (fp == NULL){
printf("Could not open file %s",filename);
return 1;
}
while (fread(str,1, 1000, fp) != NULL){
printf("%s", str);
send(sock, str, 1000, 0);
sleep(1);
}

fclose(fp);

printf("In sevrer: Printing files n");
/* Read the output a line at a time - output it. */
//while (fgets(path, sizeof(path), fp) != NULL) {
// printf("%s", path);
// send(sock, path, sizeof(path), 0);
//}
/* close */
//pclose(fp);


}

close(sock);
}

close(listen_sock);
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.