Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

accepting binary chars in socket methods

Posted on 2006-06-03
12
Medium Priority
?
373 Views
Last Modified: 2013-11-15
Hey experts,

 When you use File IO in C, you should open the file in binary format (ios::binary) in order to read/write in binary format, i.e. for example process the null character as a normal char., and not as a terminating character. However, when I am passing data via sockets using send & recv functions, the null char. is being taken as a terminating char., and I can't seem to know what kind of initialization I should do for the socket to allow it to process binary characters...any help??

P.S.: I am using Windows Platform
0
Comment
Question by:mte01
  • 4
  • 4
  • 3
  • +1
12 Comments
 
LVL 23

Accepted Solution

by:
brettmjohnson earned 840 total points
ID: 16824269
Use read() and write() instead of send() and recv().
0
 
LVL 3

Author Comment

by:mte01
ID: 16824483
>>brettmjohnson

When I used write (with the socket descriptor, data to be written, and length of data as parameters), it returned -1 (the write was not successfull); while when I was sending data using send, I was able to send the data before the null char...any idea why??
0
 
LVL 46

Assisted Solution

by:Kent Olsen
Kent Olsen earned 210 total points
ID: 16824965
Hi mte01,

After the write() fails, check the value of ERRNO.


Good Luck!
Kent
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Assisted Solution

by:Nopius
Nopius earned 390 total points
ID: 16826025
Try this, before read/write:

setmode(fd, O_BINARY);

where fd is an open socket descriptor.
0
 
LVL 3

Author Comment

by:mte01
ID: 16826095
Well it turns out that that socket descriptor (returned by the socket) function cannot be manipulated like a file descriptor (it will give bad file no. when trying to use read, write, or setmode)
0
 
LVL 27

Expert Comment

by:Nopius
ID: 16826171
It can, I guess. Please paste your code snippet here.
0
 
LVL 23

Expert Comment

by:brettmjohnson
ID: 16826195
>  Well it turns out that that socket descriptor (returned by the socket) function cannot be manipulated
> like a file descriptor (it will give bad file no. when trying to use read, write, or setmode)

Do you have a broken OS?
0
 
LVL 3

Author Comment

by:mte01
ID: 16826948
>>brettmjohnson

What do you mean by broken OS?

Guys,

I was able to do the transfer, by incrementing the asciis of the chars by one at the server, and then decrementing them by one at the client, and it worked :)...thanks for your help anyways!!
0
 
LVL 23

Expert Comment

by:brettmjohnson
ID: 16827449
> What do you mean by broken OS?

I mean an OS with a crappy sockets implementation, like Windows.
[Windows also suffers from a broken device driver design, so I can
imagine that socket vs file descriptor usage is not transparent.]
0
 
LVL 27

Expert Comment

by:Nopius
ID: 16829141
brettmjohnson, I checked setmode() in MinGW+Windows on sockets, it was working. But there where problems with char-by-char read, only int-by-int.
0
 
LVL 27

Expert Comment

by:Nopius
ID: 16829165
I mean int-by-int was the only method to read binary streams :-)
0
 
LVL 3

Author Comment

by:mte01
ID: 16830704
>> brettmjohnson, Nopius

Ahaa I see...thx for your lookup!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
Tech giants such as Amazon and Google have sold Alexa and Echo to such an extent that they have become household names. And soon they are expected to be used by commoners in their homes, ordering takeout, picking out a song, answering trivia questio…
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question