-
August 23rd, 2007, 02:04 AM
#1
How to create UDP Packets
Hi,
I want to send a image from server to client using UDP. How to send it? How to create packet ?
-
August 23rd, 2007, 12:51 PM
#2
Re: How to create UDP Packets
What have you tried, and what in your attempts is not working?
Mike
-
August 23rd, 2007, 09:23 PM
#3
Re: How to create UDP Packets
Find this book:
"Unix Network Programming" by Richard Stevens.
This is very old book (i read on 1995), but very useful to understanding
socket programming including UDP.
-
August 27th, 2007, 07:19 AM
#4
Re: How to create UDP Packets
Hi, i want to divide image file into packets. i did this in text file it worked fine but its not working in PNG file. Why its not working? i am unable to create copy of the image. Whats wrong with this code!
CODE :
#include <iostream>
#include <fstream>
using namespace std;
int main() {
f1.open("D:\\xx.png",ios::binary);
if(!f1.is_open()) {
cout<<"Unable to open file\n";
return 0;
}
f1.seekg(0,ios::end);
int length = f1.tellg();
f1.seekg(0,ios::beg);
fstream f2("xxx.png",ios:ut|ios::binary);
const int nBytes = 30720;
char *buffer = new char [nBytes + 1];
int nRead(0);
const int bytes = 30720;
char buffer[bytes + 1];
while(!f1.eof()) {
nRead = f1.read(buffer,bytes).tellg ();
if (nRead <= -1) {
int temp = length % bytes;
buffer[temp] = 0;
f2<<buffer;
}
else {
buffer[bytes] = 0;
f2<<buffer;
}
}
f1.close();
f2.close();
}
</code>
Last edited by rajprabhu2k; August 27th, 2007 at 07:24 AM.
-
August 27th, 2007, 09:32 AM
#5
Re: How to create UDP Packets
For one thing, this has nothing to do with networks.
For a second thing, you are treating a binary stream of data as if it was a null-terminated string, which it is not:
Code:
if (nRead <= -1) {
int temp = length % bytes;
buffer[temp] = 0; // why are you null-terminating this???
f2<<buffer;
}
There might be others too ...
Mike
PS: Nice try with code tags. Use square brackets, not angle brackets, like [ code ] [ /code ] (without the spaces)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|