473,387 Members | 1,619 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,387 software developers and data experts.

socket transmission problem

Hello,

when I send this bytes B4 43 71 40 A0 81 F3 32 C0 80 using socket.Send()
the receiver receives this bytes 3F 43 71 40 3F 3F 3F 32 3F 3F
why?????
Nov 16 '05 #1
9 1377
Could you please show some code so we can help?

Regards,
--
Angel J. Hernández M.
MCSD.NET
an**********@hotmail.com
http://groups.msn.com/desarrolladoresmiranda
"Dirk Reske" <_F*******@gmx.net> escribió en el mensaje
news:eI**************@TK2MSFTNGP10.phx.gbl...
Hello,

when I send this bytes B4 43 71 40 A0 81 F3 32 C0 80 using socket.Send()
the receiver receives this bytes 3F 43 71 40 3F 3F 3F 32 3F 3F
why?????

Nov 16 '05 #2
the byte array is the result of a calculation.
then I send it through socket.Send(byte[])
the receiver receive it by using socket.receive()

but the received bytes are others then the sent!

"Angel J. Hernández" <an**********@hotmail.com> schrieb im Newsbeitrag
news:uC**************@TK2MSFTNGP15.phx.gbl...
Could you please show some code so we can help?

Regards,
--
Angel J. Hernández M.
MCSD.NET
an**********@hotmail.com
http://groups.msn.com/desarrolladoresmiranda
"Dirk Reske" <_F*******@gmx.net> escribió en el mensaje
news:eI**************@TK2MSFTNGP10.phx.gbl...
Hello,

when I send this bytes B4 43 71 40 A0 81 F3 32 C0 80 using socket.Send()
the receiver receives this bytes 3F 43 71 40 3F 3F 3F 32 3F 3F
why?????


Nov 16 '05 #3
show all relevant code
Nov 16 '05 #4
.... since if your code is okay sending 1 implies receiving 1, hence show the
code...
Nov 16 '05 #5
Sending:

string Key = Authorization.GenerateKey(Lock);
Console.WriteLine(GetHex(Key)); // *1
byte[] send = Encoding.ASCII.GetBytes(Key);
this.socket.Send(send);

receiving:

while ((len = socket.Receive(input)) > 0)
{
foreach (byte bt in input)
{
if (bt != 0)
{
Console.Write(bt.ToString("X2") + " "); //Here I get other
Hex values than in *1
}
}

"Joep" <St***@DeStoep.nl> schrieb im Newsbeitrag
news:41***********************@news.xs4all.nl...
... since if your code is okay sending 1 implies receiving 1, hence show
the code...

Nov 16 '05 #6
Do us and yourself a favor, check the bytes you are sending - so after
Encoding - , you will see they are the same as the receiving bytes.
Then start thinking what you have done to your original bytes.

Willy.

"Dirk Reske" <_F*******@gmx.net> wrote in message
news:u%****************@TK2MSFTNGP09.phx.gbl...
Sending:

string Key = Authorization.GenerateKey(Lock);
Console.WriteLine(GetHex(Key)); // *1
byte[] send = Encoding.ASCII.GetBytes(Key);
this.socket.Send(send);

receiving:

while ((len = socket.Receive(input)) > 0)
{
foreach (byte bt in input)
{
if (bt != 0)
{
Console.Write(bt.ToString("X2") + " "); //Here I get other
Hex values than in *1
}
}

"Joep" <St***@DeStoep.nl> schrieb im Newsbeitrag
news:41***********************@news.xs4all.nl...
... since if your code is okay sending 1 implies receiving 1, hence show
the code...


Nov 16 '05 #7
sorry....you're all right!!

but why does my function

public static byte[] ToByteArray(string str)
{
byte[] arr = new byte[str.Length];
for (int i = 0; i < arr.Length; i++)
arr[i] = (byte)str[i];
return arr;
}

return another array then
System.Text.Encoding.ASCII.GetBytes(str) ??

"Willy Denoyette [MVP]" <wi*************@pandora.be> schrieb im Newsbeitrag
news:ut**************@TK2MSFTNGP11.phx.gbl...
Do us and yourself a favor, check the bytes you are sending - so after
Encoding - , you will see they are the same as the receiving bytes.
Then start thinking what you have done to your original bytes.

Willy.

"Dirk Reske" <_F*******@gmx.net> wrote in message
news:u%****************@TK2MSFTNGP09.phx.gbl...
Sending:

string Key = Authorization.GenerateKey(Lock);
Console.WriteLine(GetHex(Key)); // *1
byte[] send = Encoding.ASCII.GetBytes(Key);
this.socket.Send(send);

receiving:

while ((len = socket.Receive(input)) > 0)
{
foreach (byte bt in input)
{
if (bt != 0)
{
Console.Write(bt.ToString("X2") + " "); //Here I get other
Hex values than in *1
}
}

"Joep" <St***@DeStoep.nl> schrieb im Newsbeitrag
news:41***********************@news.xs4all.nl...
... since if your code is okay sending 1 implies receiving 1, hence show
the code...



Nov 16 '05 #8

"Dirk Reske" <_F*******@gmx.net> wrote in message
news:u6**************@TK2MSFTNGP12.phx.gbl...
sorry....you're all right!!

but why does my function

public static byte[] ToByteArray(string str)
{
byte[] arr = new byte[str.Length];
for (int i = 0; i < arr.Length; i++)
arr[i] = (byte)str[i];
return arr;
}

return another array then
System.Text.Encoding.ASCII.GetBytes(str) ??


Because your function truncates the unicode character to lower 8-bits,
whereas the ASCII encoding is defined as 7-bit, and all characters out of
the range 0..127 are converted to '?' (which is the 0x3F you have
encountered at the beginning).

It's generally not a good idea to use strings as a storage for binary data,
unless you really know what you're doing. I suggest you rewrite the
Authorization.GenerateKey() function to return byte[] instead of string.

HTH,
Stefan


Nov 16 '05 #9
yes, I know, but its a text based protocol.
I have to send "$Key <key>"....

"©tefan ©imek" <si********@kascomp.blah.sk> schrieb im Newsbeitrag
news:eC*************@TK2MSFTNGP11.phx.gbl...

"Dirk Reske" <_F*******@gmx.net> wrote in message
news:u6**************@TK2MSFTNGP12.phx.gbl...
sorry....you're all right!!

but why does my function

public static byte[] ToByteArray(string str)
{
byte[] arr = new byte[str.Length];
for (int i = 0; i < arr.Length; i++)
arr[i] = (byte)str[i];
return arr;
}

return another array then
System.Text.Encoding.ASCII.GetBytes(str) ??


Because your function truncates the unicode character to lower 8-bits,
whereas the ASCII encoding is defined as 7-bit, and all characters out of
the range 0..127 are converted to '?' (which is the 0x3F you have
encountered at the beginning).

It's generally not a good idea to use strings as a storage for binary
data, unless you really know what you're doing. I suggest you rewrite the
Authorization.GenerateKey() function to return byte[] instead of string.

HTH,
Stefan

Nov 16 '05 #10

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

Similar topics

4
by: 0k | last post by:
Hi everyone, I am trying to write a small app that sends multicast udp packets using a socket object. I have more than one NIC on my PC and the following code works OK only if I disable all the...
4
by: Chris Tanger | last post by:
Context: C# System.Net.Sockets Socket created with constructor prarmeters Internetwork, Stream and TCP everything else is left at the default parameters and options except linger may be changed...
1
by: Laura T. | last post by:
Hi, I've this kind a program, using sockets to communicate with the clients. One of the clients can be a web browser (like IE). When using IE as a client, the transmission blocks completely, and...
0
by: Carl Waldbieser | last post by:
I am trying to understand how the SSL object in the socket module is supposed to be used. From looking at the documentation, I can work out that you need to pass a socket into the ssl() function,...
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...
5
by: Tiger | last post by:
Hi, I try to send a packet with raw socket but I have an error with ethereal sniffer on windows xp. I can't find any solution on the net. :( Could anybody help with that problem? my code :...
2
by: Ben | last post by:
I need to send data from a client to a server. In the server code I have: s = ServerSocket.Accept() If (s.Connected = False) Then MsgBox("Unable to connect", , "Server Error") Exit Sub End...
3
Sagittarius
by: Sagittarius | last post by:
Hi there. I have a problem concerning an UDP socket in C++ (Winsock). The next paragraphs is merely to explain the system I am working on. If U want to skip it, I have marked the question in...
6
by: White Spirit | last post by:
I have the following code to send a packet to a remote socket and receive a response in return: System.Net.Sockets.Socket locSocket = new System.Net.Sockets.Socket (AddressFamily.InterNetwork,...
3
by: A. W. Dunstan | last post by:
I have an application that wants to open a Socket, write data and close the socket. A persistent connection would be nice, but it's intended to operate in an environment where the network...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.