NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

#include<sys/types.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <netdb.h>
#include <sys/socket.h>
#include <time.h>
//#include<string>
//#include "port.h"

#define SERVICE_PORT 21234
#define BUFLEN 512
#define MSGS 5 /* number of messages to send */
#define SERVICE_PORT 21234



//time_t start = time(NULL);


//Do your work


//time_t end = time(NULL);
//std::cout<<"Execution Time: "<< (double)(end-start)<<" Seconds"<<std::endl;

int main(void)
{ int seqno = 0;
struct sockaddr_in myaddr, remaddr;
socklen_t addrlen = sizeof(remaddr);
int fd, i, slen=sizeof(remaddr);
char buffer[BUFLEN]; //Packet Buffer //
char buf[BUFLEN]; /* message buffer */
int recvlen;
int count =0;
int number = 32; /* # bytes in acknowledgement message */
char *server = "10.0.2.15"; /* change this to use a different server */

/* create a socket */

if ((fd=socket(AF_INET, SOCK_DGRAM, 0))==-1)
printf("socket createdn");

/* bind it to all local addresses and pick any port number */

memset((char *)&myaddr, 0, sizeof(myaddr));
myaddr.sin_family = AF_INET;
myaddr.sin_addr.s_addr = htonl(INADDR_ANY);
myaddr.sin_port = htons(0);

if (bind(fd, (struct sockaddr *)&myaddr, sizeof(myaddr)) < 0) {
perror("bind failed");
return 0;
}

/* now define remaddr, the address to whom we want to send messages */
/* For convenience, the host address is expressed as a numeric IP address */
/* that we will convert to a binary format via inet_aton */

memset((char *) &remaddr, 0, sizeof(remaddr));
remaddr.sin_family = AF_INET;
remaddr.sin_port = htons(SERVICE_PORT);
if (inet_aton(server, &remaddr.sin_addr)==0) {
fprintf(stderr, "inet_aton() failedn");
exit(1);
}


FILE *file;
file = fopen("first.doc","rb");
while(!feof(file)){
//time_t start = time(NULL);
recvlen = fread(&buffer,sizeof(buffer),1,file);
//printf("%dn",recvlen);
printf("%sn",buffer);
char *intStr;
sprintf(intStr, "%d", recvlen);
//printf("%dn",sizeof(buffer));
count = count + sizeof(buffer);
sendto(fd, buffer, sizeof(buffer), 0, (struct sockaddr *)&remaddr, slen);
//send(new_socket,buffer,sizeof(buffer),0);
if(recvfrom(fd, buf, sizeof(buf), 0, (struct sockaddr *)&remaddr, &addrlen)>0){

printf("%s n",buf);
seqno =seqno+1;
}
//time_t end = time(NULL);
//printf("%f",(double)end-start);
sendto(fd, intStr, sizeof(intStr), 0, (struct sockaddr *)&remaddr, slen);
}
printf("Outside of loppn");

sendto(fd, "0", sizeof(recvlen), 0, (struct sockaddr *)&remaddr, slen);
printf("Total File Length : %dn",count);

//printf("%s",buffer);
fclose(file);
printf("File Closed");
//send(new_socket , hello , strlen(hello) , 0 );


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