954,480 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Packet send

does someone know a code in c that will send a complete ASCII file in 128 byte packets to another file? So The sender takes the ASCII file as input and sends a 128 byte packet on the data queue

R3Slick
Light Poster
27 posts since Nov 2009
Reputation Points: 6
Solved Threads: 1
 

I'm confused about what you mean by send to a data file? Or data queue? Are you talking about sockets -- sending packets via sockets to another computer? Or are you talking about copying a file 128 bytes at a time ?

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

The second part of your question is what i want to do...Im not using sockets. So something like this will read the file. The arg[2] is the second argument in the command line so this will be the name of the file. But I need to convert that file into 128 packets or 122 byte packets so I can insert my checksum and a header to it too.

FILE * f1= fopen(arg[2],"r"); ///reads the file and that how far I am


Im confused myself. All i know is I have to read the file and convert it to packets then add a checksum and a header and then transfer it into a queue. So those packet will be in the queue and then I need to write a receive file that will read the packets and checksum them and write the results into a new file then i need to compare the original file with the file the receiver created to make sure they match...Im new to c and networking and this is way too hard.

R3Slick
Light Poster
27 posts since Nov 2009
Reputation Points: 6
Solved Threads: 1
 

open the file in binary mode then read it 128 bytes at a time

FILE* fp = fopen(arg[2],"rb");
char buf[128];
size_t nBytesRead;
while( (nBytesRead = fread(buf, 1, sizeof(buf), fp)) > 0)
{

}
Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

thank you, that helped so much.

R3Slick
Light Poster
27 posts since Nov 2009
Reputation Points: 6
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: