P
Prabhu
Hi,
We are having problem in converting a byte array to string, The byte array
has char(174), char(175), char(240), char(242) and char(247) as delimiters
for the message.
when we use "System.Text.Encoding.ASCII.GetString(bytearray)" of .Net
library, we found that the char (delimiters) specified above are replaced
with different char.
Can any one help me in this ?
My sample program is,
using System;
using System.Text;
using System.Net.Sockets;
namespace StrideAPIParse
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
public static char PACKET_BEGIN_DELIMIT = (char)175;
public static char HEADER_DELIMIT = (char)240;
public static char RECORD_FIELD_DELIMIT = (char)242;
public static char RECORD_DELIMIT = (char)247;
public static char PACKET_END_DELIMIT = (char)174;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
TcpClient tcpClient = new TcpClient();
tcpClient.Connect("172.16.10.164", 5403);
NetworkStream networkStream = tcpClient.GetStream();
byte[] bytes = new byte[tcpClient.ReceiveBufferSize];
int readleagth = networkStream.Read(bytes, 0, (int)
tcpClient.ReceiveBufferSize);
bytes[readleagth] = 0;
String stridemsg = Encoding.ASCII.GetString(bytes);
string [] msg = stridemsg.Split(HEADER_DELIMIT);
foreach(string m in msg)
{
Console.WriteLine(m);
}
tcpClient.Close();
Console.ReadLine();
}
}
}
We are having problem in converting a byte array to string, The byte array
has char(174), char(175), char(240), char(242) and char(247) as delimiters
for the message.
when we use "System.Text.Encoding.ASCII.GetString(bytearray)" of .Net
library, we found that the char (delimiters) specified above are replaced
with different char.
Can any one help me in this ?
My sample program is,
using System;
using System.Text;
using System.Net.Sockets;
namespace StrideAPIParse
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
public static char PACKET_BEGIN_DELIMIT = (char)175;
public static char HEADER_DELIMIT = (char)240;
public static char RECORD_FIELD_DELIMIT = (char)242;
public static char RECORD_DELIMIT = (char)247;
public static char PACKET_END_DELIMIT = (char)174;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
TcpClient tcpClient = new TcpClient();
tcpClient.Connect("172.16.10.164", 5403);
NetworkStream networkStream = tcpClient.GetStream();
byte[] bytes = new byte[tcpClient.ReceiveBufferSize];
int readleagth = networkStream.Read(bytes, 0, (int)
tcpClient.ReceiveBufferSize);
bytes[readleagth] = 0;
String stridemsg = Encoding.ASCII.GetString(bytes);
string [] msg = stridemsg.Split(HEADER_DELIMIT);
foreach(string m in msg)
{
Console.WriteLine(m);
}
tcpClient.Close();
Console.ReadLine();
}
}
}