473,385 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Socket - send bytes to 255

I'm using sockets. I need to send bytes without alternation from 0-255. When
I use the standard,

Byte[] bytestuff = System.Text.Encoding.ASCII.GetBytes(stuff.ToCharAr ray());
tSocket.Send(bytestuff,bytestuff.Length,0);

It encodes most characters to ? past asci 127. I beleive that's because of
the Encoding,ASCII. How can I send info preserving the raw bits for asci
128-255?

Thanks in advance.

Nov 17 '05 #1
3 4833
Dave wrote:
I'm using sockets. I need to send bytes without alternation from 0-255. When
I use the standard,

Byte[] bytestuff = System.Text.Encoding.ASCII.GetBytes(stuff.ToCharAr ray());
tSocket.Send(bytestuff,bytestuff.Length,0);

It encodes most characters to ? past asci 127. I beleive that's because of
the Encoding,ASCII. How can I send info preserving the raw bits for asci
128-255?


Use the System.Text.Encoding.UTF8 object. Also, you don't need to
convert the string to a char[], as GetBytes() will take either type.

--
--Mike Edenfield
KutuluWare Software Services
ku****@not.kutulu.not.org <be positive to contact>
Nov 17 '05 #2
Hi,

It's the Encoding, try UTF8 instead

now, if you are sending it to a socket stream you have to make sure that
both ends work the same.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Dave" <Da**@discussions.microsoft.com> wrote in message
news:B1**********************************@microsof t.com...
I'm using sockets. I need to send bytes without alternation from 0-255.
When
I use the standard,

Byte[] bytestuff =
System.Text.Encoding.ASCII.GetBytes(stuff.ToCharAr ray());
tSocket.Send(bytestuff,bytestuff.Length,0);

It encodes most characters to ? past asci 127. I beleive that's because of
the Encoding,ASCII. How can I send info preserving the raw bits for asci
128-255?

Thanks in advance.

Nov 17 '05 #3
Dave <Da**@discussions.microsoft.com> wrote:
I'm using sockets. I need to send bytes without alternation from 0-255. When
I use the standard,

Byte[] bytestuff = System.Text.Encoding.ASCII.GetBytes(stuff.ToCharAr ray());
tSocket.Send(bytestuff,bytestuff.Length,0);

It encodes most characters to ? past asci 127. I beleive that's because of
the Encoding,ASCII. How can I send info preserving the raw bits for asci
128-255?


There are no ASCII characters beyond 127.

If you want to send bytes without alteration, you shouldn't be
converting them into text to start with.

See http://www.pobox.com/~skeet/csharp/unicode.html

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Kitchen Bin | last post by:
Hi. I am trying to use Sockets to do multiple Send and Receives via HTTP (not simultaneously). A first pair of Send/Receives works fine and sure enough I receive HTML back, but the next...
3
by: Ricardo Quintanilla | last post by:
i had a problem whom i do not know how to explain. i was using a TcpClient (System.Net.Sockets.TcpClient) object to send and receive data to an AS400 socket. Two months ago it started to work...
2
by: Droopy | last post by:
Hi, I try to implement a reusable socket class to send and receive data. It seems to work but I have 2 problems : 1) I rely on Socket.Available to detect that the connection is closed (no...
2
by: Nuno Magalhaes | last post by:
I've got a simple problem I guess. How do I know when a connection is terminated without losing any data? I do something like the code below, but sometimes between socket.Receive and socket.Send...
13
by: coloradowebdev | last post by:
i am working on basically a proxy server that handles requests via remoting from clients and executes transactions against a third-party server via TCP. the remoting site works like a champ. my...
9
by: Macca | last post by:
Hi, I have a synchronous socket server which my app uses to read data from clients. To test this I have a simulated client that sends 100 byte packets. I have set up the socket server so...
2
by: djc | last post by:
I read a network programming book (based on framework 1.1) which indicated that you should 'never' use the RecieveTimeout or the SendTimeout 'socket options' on TCP sockets or you may loose data. I...
4
by: SpreadTooThin | last post by:
client: import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(("192.168.1.101", 8080)) print 'Connected' s.send('ABCD') buffer = s.recv(4) print buffer s.send('exit')
14
by: ahlongxp | last post by:
Hi, everyone, I'm implementing a simple client/server protocol. Now I've got a situation: client will send server command,header paires and optionally body. server checks headers and decides...
4
by: Zytan | last post by:
This may be the dumbest question of all time, but... When I set the packet size, does it mean ALL packets are that size, no matter what? Let's say the packet size is 8KB, and I send a 5 byte...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.