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

Problem sending Hexadecimal as part of a string using socket.send

Hi, I'm able to make connection to a server using socket connection.
However, when I send a command string the server just ignores it. All
command string needs to start with "0xF9" at Byte 0. During the run-time
debug, I see it to be "u" with a "~" on top of it. Is that OxF9? Can
someone tell me what I'm doing wrong?
Thanks, Alpha

private void Connect(String server, String message)
{
//Socket Connect
try
{
//create a new client socket ...
m_socClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp);
String szIPSelected = "192.168.1.7";
String szPort = "22333";
int alPort = System.Convert.ToInt16 (szPort,10);

System.Net.IPAddress remoteIPAddress =
System.Net.IPAddress.Parse(szIPSelected);
System.Net.IPEndPoint remoteEndPoint = new
System.Net.IPEndPoint(remoteIPAddress, alPort);
m_socClient.Connect(remoteEndPoint);
// String message = "Hello There";
// byte[] byData = System.Text.Encoding.ASCII.GetBytes(message);
// m_socClient.Send(byData);

}
catch (SocketException se)
{
MessageBox.Show ( se.Message );
}
//Send ATS Data
try
{
byte[] byData = System.Text.Encoding.ASCII.GetBytes(message);
m_socClient.Send (byData);
}
catch(SocketException se)
{
MessageBox.Show (se.Message );
}
//Receive ATS Data
// Receive the TcpServer.response.

try
{
byte [] buffer = new byte[256];
int iRx = m_socClient.Receive (buffer);
char[] chars = new char[iRx];

System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
int charLen = d.GetChars(buffer, 0, iRx, chars, 0);
System.String Retmessage = new System.String(chars);
MessageBox.Show("Reply from ATS server: "+ Retmessage.ToString() ,
"ATS Reply", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch(SocketException se)
{
MessageBox.Show (se.Message );
}
//Close Socket Connection
m_socClient.Close ();

}

private void menuItem9_Click(object sender, System.EventArgs e)
{
string Message;
Message = "\xF9" + "1800000007CATT,TO";
Connect("Map", Message);
}
Dec 23 '05 #1
2 5241
Alpha,

0xF9 is definitely not in the ASCII character set, so it's very possible
that the character you see is correct. However, this doesn't mean that what
you are sending is wrong. It just is that the "u" character is the
representation of that byte. However, how the service interprets it is
completely irrelevant.

If you actually want to send the byte F9, then do not send it as a
string. Rather, create the byte array with this value yourself, and send
that.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Alpha" <Al***@discussions.microsoft.com> wrote in message
news:9E**********************************@microsof t.com...
Hi, I'm able to make connection to a server using socket connection.
However, when I send a command string the server just ignores it. All
command string needs to start with "0xF9" at Byte 0. During the run-time
debug, I see it to be "u" with a "~" on top of it. Is that OxF9? Can
someone tell me what I'm doing wrong?
Thanks, Alpha

private void Connect(String server, String message)
{
//Socket Connect
try
{
//create a new client socket ...
m_socClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp);
String szIPSelected = "192.168.1.7";
String szPort = "22333";
int alPort = System.Convert.ToInt16 (szPort,10);

System.Net.IPAddress remoteIPAddress =
System.Net.IPAddress.Parse(szIPSelected);
System.Net.IPEndPoint remoteEndPoint = new
System.Net.IPEndPoint(remoteIPAddress, alPort);
m_socClient.Connect(remoteEndPoint);
// String message = "Hello There";
// byte[] byData = System.Text.Encoding.ASCII.GetBytes(message);
// m_socClient.Send(byData);

}
catch (SocketException se)
{
MessageBox.Show ( se.Message );
}
//Send ATS Data
try
{
byte[] byData = System.Text.Encoding.ASCII.GetBytes(message);
m_socClient.Send (byData);
}
catch(SocketException se)
{
MessageBox.Show (se.Message );
}
//Receive ATS Data
// Receive the TcpServer.response.

try
{
byte [] buffer = new byte[256];
int iRx = m_socClient.Receive (buffer);
char[] chars = new char[iRx];

System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
int charLen = d.GetChars(buffer, 0, iRx, chars, 0);
System.String Retmessage = new System.String(chars);
MessageBox.Show("Reply from ATS server: "+ Retmessage.ToString() ,
"ATS Reply", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch(SocketException se)
{
MessageBox.Show (se.Message );
}
//Close Socket Connection
m_socClient.Close ();

}

private void menuItem9_Click(object sender, System.EventArgs e)
{
string Message;
Message = "\xF9" + "1800000007CATT,TO";
Connect("Map", Message);
}

Dec 24 '05 #2
Thank you Nicholas for the help. Can you show me how to send F9 and the rest
of my message in the bye array?

Thanks, Alpha

"Nicholas Paldino [.NET/C# MVP]" wrote:
Alpha,

0xF9 is definitely not in the ASCII character set, so it's very possible
that the character you see is correct. However, this doesn't mean that what
you are sending is wrong. It just is that the "u" character is the
representation of that byte. However, how the service interprets it is
completely irrelevant.

If you actually want to send the byte F9, then do not send it as a
string. Rather, create the byte array with this value yourself, and send
that.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Alpha" <Al***@discussions.microsoft.com> wrote in message
news:9E**********************************@microsof t.com...
Hi, I'm able to make connection to a server using socket connection.
However, when I send a command string the server just ignores it. All
command string needs to start with "0xF9" at Byte 0. During the run-time
debug, I see it to be "u" with a "~" on top of it. Is that OxF9? Can
someone tell me what I'm doing wrong?
Thanks, Alpha

private void Connect(String server, String message)
{
//Socket Connect
try
{
//create a new client socket ...
m_socClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp);
String szIPSelected = "192.168.1.7";
String szPort = "22333";
int alPort = System.Convert.ToInt16 (szPort,10);

System.Net.IPAddress remoteIPAddress =
System.Net.IPAddress.Parse(szIPSelected);
System.Net.IPEndPoint remoteEndPoint = new
System.Net.IPEndPoint(remoteIPAddress, alPort);
m_socClient.Connect(remoteEndPoint);
// String message = "Hello There";
// byte[] byData = System.Text.Encoding.ASCII.GetBytes(message);
// m_socClient.Send(byData);

}
catch (SocketException se)
{
MessageBox.Show ( se.Message );
}
//Send ATS Data
try
{
byte[] byData = System.Text.Encoding.ASCII.GetBytes(message);
m_socClient.Send (byData);
}
catch(SocketException se)
{
MessageBox.Show (se.Message );
}
//Receive ATS Data
// Receive the TcpServer.response.

try
{
byte [] buffer = new byte[256];
int iRx = m_socClient.Receive (buffer);
char[] chars = new char[iRx];

System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
int charLen = d.GetChars(buffer, 0, iRx, chars, 0);
System.String Retmessage = new System.String(chars);
MessageBox.Show("Reply from ATS server: "+ Retmessage.ToString() ,
"ATS Reply", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch(SocketException se)
{
MessageBox.Show (se.Message );
}
//Close Socket Connection
m_socClient.Close ();

}

private void menuItem9_Click(object sender, System.EventArgs e)
{
string Message;
Message = "\xF9" + "1800000007CATT,TO";
Connect("Map", Message);
}


Dec 27 '05 #3

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

Similar topics

11
by: Jeff Crouse | last post by:
In my project, I have successfully opened a sock_stream style socket connection between two processes and am trying to send 'buffer' to a connected client, 'fd'. The following code works just...
0
by: Lynne | last post by:
I am using the C# asynchronous socket functionality for a server, and it appears to work fine if I just receive data and echo it back to the client. The problem occurs when I try to handle sending...
11
by: Abhishek | last post by:
I have a problem transfering files using sockets from pocket pc(.net compact c#) to desktop(not using .net just mfc and sockets 2 API). The socket communication is not a issue and I am able to...
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...
4
by: yaron | last post by:
Hi, I have a problem when sending data over TCP socket from c# client to java server. the connection established ok, but i can't send data from c# client to java server. it's work ok with...
11
by: zaebos | last post by:
hi, i have this code which is part of a main program, to email from within the program a log file: int MailIt (char *mailserver, char *emailto, char *emailfrom, char *emailsubject, char...
3
by: BuddyWork | last post by:
Hello, Could someone please explain why the Socket.Send is slow to send to the same process it sending from. Eg. Process1 calls Socket.Send which sends to the same IP address and port, the...
0
by: Buddy Home | last post by:
There is two examples of code. Example 1. Send and Receive within the same process. Put this code in a console app called SendAndReceive and run the code. using System; using...
2
by: Danny | last post by:
Hi all, Trying to send mail with System.Net.SmtpClient, using very simple code just for testing: SmtpClient smtp = new SmtpClient("mail.server.com", 25); smtp.Credentials = new...
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...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.