Support for UTF-8 encoding.
This commit is contained in:
parent
04376cc2cf
commit
7c548446e9
|
@ -51,7 +51,7 @@
|
||||||
<CheckForOverflowUnderflow>false</CheckForOverflowUnderflow>
|
<CheckForOverflowUnderflow>false</CheckForOverflowUnderflow>
|
||||||
<ConfigurationOverrideFile>
|
<ConfigurationOverrideFile>
|
||||||
</ConfigurationOverrideFile>
|
</ConfigurationOverrideFile>
|
||||||
<DefineConstants>DEBUG</DefineConstants>
|
<DefineConstants>TRACE;DEBUG</DefineConstants>
|
||||||
<DocumentationFile>bmxnet.xml</DocumentationFile>
|
<DocumentationFile>bmxnet.xml</DocumentationFile>
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
<FileAlignment>4096</FileAlignment>
|
<FileAlignment>4096</FileAlignment>
|
||||||
|
@ -72,8 +72,7 @@
|
||||||
<CheckForOverflowUnderflow>false</CheckForOverflowUnderflow>
|
<CheckForOverflowUnderflow>false</CheckForOverflowUnderflow>
|
||||||
<ConfigurationOverrideFile>
|
<ConfigurationOverrideFile>
|
||||||
</ConfigurationOverrideFile>
|
</ConfigurationOverrideFile>
|
||||||
<DefineConstants>
|
<DefineConstants>TRACE;DEBUG</DefineConstants>
|
||||||
</DefineConstants>
|
|
||||||
<DocumentationFile>bmxnet.xml</DocumentationFile>
|
<DocumentationFile>bmxnet.xml</DocumentationFile>
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
<FileAlignment>4096</FileAlignment>
|
<FileAlignment>4096</FileAlignment>
|
||||||
|
|
|
@ -845,9 +845,9 @@ namespace IndianHealthService.BMXNet
|
||||||
{
|
{
|
||||||
NetworkStream ns = tcpClient.GetStream();
|
NetworkStream ns = tcpClient.GetStream();
|
||||||
|
|
||||||
int nTimeOut = this.m_nReceiveTimeout;
|
int nTimeOut = this.m_nReceiveTimeout; //timeout
|
||||||
int nCnt = 0;
|
int nCnt = 0; //number of times trying to get a message from the client
|
||||||
int nTimeElapsed = 0;
|
int nTimeElapsed = 0; //compare with timeout; increment 50 ms everytime.
|
||||||
while (ns.DataAvailable == false)
|
while (ns.DataAvailable == false)
|
||||||
{
|
{
|
||||||
if (nCnt > 9999)
|
if (nCnt > 9999)
|
||||||
|
@ -860,36 +860,36 @@ namespace IndianHealthService.BMXNet
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.Assert(ns.DataAvailable == true);
|
Debug.Assert(ns.DataAvailable == true);
|
||||||
if (ns.DataAvailable == false)
|
if (ns.DataAvailable == false) //if still false, then we timed out.
|
||||||
{
|
{
|
||||||
this.CloseConnection();
|
this.CloseConnection();
|
||||||
throw new Exception("BMXNetLib.ReceiveString timeout. Connection Closed.");
|
throw new Exception("BMXNetLib.ReceiveString timeout. Connection Closed.");
|
||||||
//return "";
|
//return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] bReadBuffer = new byte[1024];
|
byte[] bReadBuffer = new byte[1024]; //byte buffer
|
||||||
string sReadBuffer = "";
|
string sReadBuffer = ""; //string buffer
|
||||||
StringBuilder sbAll = new StringBuilder("", 1024);
|
StringBuilder sbAll = new StringBuilder("", 1024); //string builder
|
||||||
int numberOfBytesRead = 0;
|
int numberOfBytesRead = 0;
|
||||||
|
|
||||||
// Incoming message may be larger than the buffer size.
|
// Incoming message may be larger than the buffer size.
|
||||||
|
|
||||||
bool bFinished = false;
|
bool bFinished = false; //finished reading?
|
||||||
int nFind = -1;
|
int nFind = -1; //Position of $C(4) (End of Transmission)
|
||||||
bool bStarted = false;
|
bool bStarted = false; //Is the buffer started?
|
||||||
int lpBuf = 0;
|
int lpBuf = 0; //?
|
||||||
string sError = "";
|
string sError = ""; //?
|
||||||
string sAppError = "";
|
string sAppError = ""; //?
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
numberOfBytesRead = ns.Read(bReadBuffer, 0, bReadBuffer.Length);
|
numberOfBytesRead = ns.Read(bReadBuffer, 0, bReadBuffer.Length); // read 1024 characters
|
||||||
if ((numberOfBytesRead == 1)&&(bStarted == false))
|
if ((numberOfBytesRead == 1)&&(bStarted == false)) // if only one byte read, try again in 15 ms
|
||||||
{
|
{
|
||||||
Thread.Sleep(15);
|
Thread.Sleep(15);
|
||||||
numberOfBytesRead += ns.Read(bReadBuffer,1, bReadBuffer.Length-1);
|
numberOfBytesRead += ns.Read(bReadBuffer,1, bReadBuffer.Length-1); //skip the first one of course
|
||||||
//Debug.Write("ReceiveString waiting for data...\n");
|
//Debug.Write("ReceiveString waiting for data...\n");
|
||||||
}
|
}
|
||||||
if (bStarted == false)
|
if (bStarted == false) //if this is the first transmission process error info
|
||||||
{
|
{
|
||||||
//Process error info at beginning of returned string
|
//Process error info at beginning of returned string
|
||||||
int nErrLen = bReadBuffer[0];
|
int nErrLen = bReadBuffer[0];
|
||||||
|
@ -909,15 +909,16 @@ namespace IndianHealthService.BMXNet
|
||||||
bStarted = true;
|
bStarted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
nFind = FindChar(bReadBuffer, (char) 4);
|
nFind = FindChar(bReadBuffer, (char) 4); //find end of transmission chracter
|
||||||
if (nFind > -1)
|
if (nFind > -1) // if found
|
||||||
bFinished = true;
|
bFinished = true; //then we are finished
|
||||||
Debug.Assert(numberOfBytesRead > -1);
|
Debug.Assert(numberOfBytesRead > -1); // this must be true
|
||||||
sReadBuffer = m_Encoding.GetString(bReadBuffer, lpBuf, numberOfBytesRead);
|
sReadBuffer = m_Encoding.GetString(bReadBuffer, lpBuf, numberOfBytesRead);
|
||||||
lpBuf = 0;
|
lpBuf = 0;
|
||||||
if (nFind > -1)
|
if (nFind > -1)
|
||||||
{
|
{
|
||||||
sbAll.Append(sReadBuffer, 0, numberOfBytesRead -1);
|
//sbAll.Append(sReadBuffer, 0, numberOfBytesRead -1); //utf8
|
||||||
|
sbAll.Append(sReadBuffer, 0, sReadBuffer.Length - 1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue