M
mscirri
The code below is what I am using to asynchronously get data from a
PocketPC device. The data comes in fine in blocks of 1024 bytes but
even when I send no data from the PocketPC constant blocks of 1024 with
all values set to Null arrive. Other than examine a block of 1024 to
see if the entire block is null, is there any other way to determine if
, say a chat message "Hi Charlie" has been received completely?
private ArrayList aryIncomingData = new ArrayList(); // pretty much a
byte[], easier to manage an ArrayList
public void WaitForData()
{
if ( pfnCallBack == null )
pfnCallBack = new AsyncCallback (OnDataReceived);
// now start to listen for any data...
m_asynResult =
sckInteractive.BeginReceive
(m_DataBuffer,0,m_DataBuffer.Length,SocketFlags.None,pfnCallBack,null);
}
public void OnDataReceived(IAsyncResult asyn)
{
//end receive...
int iRx = 0 ;
iRx = sckInteractive.EndReceive (asyn);
char[] chars = new char[iRx + 1];
System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
int charLen = d.GetChars(m_DataBuffer, 0, iRx, chars, 0);
System.String szData = new System.String(chars);
System.Text.ASCIIEncoding asc = new ASCIIEncoding();
byte[] dataBytes = asc.GetBytes(szData);
LoadIncomingData(this.m_DataBuffer);
WaitForData();
}
private bool LoadIncomingData(byte[] data)
{
foreach (byte b in data)
{
aryIncomingData.Add(b);
}
return true;
}
PocketPC device. The data comes in fine in blocks of 1024 bytes but
even when I send no data from the PocketPC constant blocks of 1024 with
all values set to Null arrive. Other than examine a block of 1024 to
see if the entire block is null, is there any other way to determine if
, say a chat message "Hi Charlie" has been received completely?
private ArrayList aryIncomingData = new ArrayList(); // pretty much a
byte[], easier to manage an ArrayList
public void WaitForData()
{
if ( pfnCallBack == null )
pfnCallBack = new AsyncCallback (OnDataReceived);
// now start to listen for any data...
m_asynResult =
sckInteractive.BeginReceive
(m_DataBuffer,0,m_DataBuffer.Length,SocketFlags.None,pfnCallBack,null);
}
public void OnDataReceived(IAsyncResult asyn)
{
//end receive...
int iRx = 0 ;
iRx = sckInteractive.EndReceive (asyn);
char[] chars = new char[iRx + 1];
System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
int charLen = d.GetChars(m_DataBuffer, 0, iRx, chars, 0);
System.String szData = new System.String(chars);
System.Text.ASCIIEncoding asc = new ASCIIEncoding();
byte[] dataBytes = asc.GetBytes(szData);
LoadIncomingData(this.m_DataBuffer);
WaitForData();
}
private bool LoadIncomingData(byte[] data)
{
foreach (byte b in data)
{
aryIncomingData.Add(b);
}
return true;
}