 |
 |
Sending Image data over a stream
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
I'm crossing my fingers that people aren't going to tell me to scrap everything I did this weekend, but here we go:
I've been using AsyncSocket to set up a socket connection between two remote computers and sending data between them has been pretty easy. Where I've run into a delimmia is when I try to send image data instead of just text. What has been working is using NSArchiver to create a data instance of a couple NSString's. What hasn't been working is doing the same thing with one of the things stored in the NSArray is an NSImage. I can archive the array fine, but when I try to send it, the receiver gets a lot of errors as if it's receiving the archived data in chunks (*** End of archive encountered prematurely at 204). So... does anyone know how to fix my problems by:
a) not requiring me to throw out everything I've done
b) !a
Thanks,
Matt Fahrenbacher
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Nov 2001
Location: State of Denial
Status:
Offline
|
|
Have you tried simply sending the raw image data, unarchived, through the stream? Or maybe, try sending a single representation of the image if that's all you need (if it's from a single-image file, or something). I suppose you could try putting the image data into an NSData object and archiving that, too.
Honestly, I'd have to mess about with it myself to know if any of these ideas will work, but I thought I'd throw something out there since no one's replied yet.
|
|
[Wevah setPostCount:[Wevah postCount] + 1];
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
I had played with that before, and was still getting the problem. It seems like it won't read more than about 204 bytes of data... but when I try to set the defines in the AsyncSocket class to be suffieciently large, it still hits a problem. My *guess* is that some of the image data is being interpreted as a new line datat charachter... I'm fearful that I'm going to have to search through that data file before transmision, swap all those data sections with something else, then undo the process on transmission.
:shudders:
Matt Fahrenbacher
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Nov 2001
Location: State of Denial
Status:
Offline
|
|
Ah, that could be...it would definitely be unfortunate if that was the case. Is there no function in the socket class you're using to read as raw data instead of a string? Or is that also messing up?
|
|
[Wevah setPostCount:[Wevah postCount] + 1];
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
It's reading the whole thing as raw data - that's not the problem. The problem is one of 2 things:
a) I can't send enough raw data at one time, so it segments the data.
b) The image data contains byte representation that matches @"\n"'s data representation, and so when that data is encoutnered, the socket thinks the read is over.
Matt Fahrenbacher
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Nov 2001
Location: State of Denial
Status:
Offline
|
|
It just seems weird to me that a newline would terminate the stream.
|
|
[Wevah setPostCount:[Wevah postCount] + 1];
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
Originally posted by Ghoser777:
It's reading the whole thing as raw data - that's not the problem. The problem is one of 2 things:
a) I can't send enough raw data at one time, so it segments the data.
b) The image data contains byte representation that matches @"\n"'s data representation, and so when that data is encoutnered, the socket thinks the read is over.
You should be able to determine which it is just by checking the 204th (or whatever) byte of the data to see if it's a terminator.
I suspect it's a), but this should allow you to determine conclusively.
|
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
Okay, it's clearly a). What I had to do was increase the READALL_CHUNKSIZE and WRITE_CHUNKSIZE up to something big enough (i.e. 10,000,000 bytes will do for the image I'm transfering... I think it's about 2 megabytes, but I'll try to cut that down in the future) and I had to modify the readData methods to always readAllAvailable... although that has the problem of causing my app to work itself to death after that... I'll keep working on fixing that now.
Matt Fahrenbacher
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
Geesh, out of 2,000,000 bytes (or is it bits...?) of data... I'm missing ONE bit/byte of data. Somewhere in the concatenation process of the segments I miss out on one piece... grr...
Matt Fahrenbacher
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
BWAHAHAHA! I win  Some of the data I was losing was due to some of the image data containing new line characters as encoded data (weird) so I had to send the length of the image across the stream first and do some checking if it was time to finish reading the image, and if not, then don't parse out the new line character because that's really image data.
Matt Fahrenbacher
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Nov 2001
Location: State of Denial
Status:
Offline
|
|
HOORAY!
I'm glad you got it sorted!
|
|
[Wevah setPostCount:[Wevah postCount] + 1];
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|