Hi folks,
I am sending a string over a socket from a C# app to a native C++ app.
I embed the unicode symbol for the pound sign in the string being
sent. When I read data from the socket, I find that a 0xC2 has been
added into the input stream right before the pound symbol.
C# fragment :
TcpClient skt = null;
StreamWriter wrt = null;
try {
skt = local.AcceptTcp Client();
skt.NoDelay = true; //no buffering!
NetworkStream ns = skt.GetStream() ;
string result = "STATUS|\u00A37 .89 (GBP)|
sess"
wrt = new StreamWriter(ns );
//results are EOL delimited
wrt.WriteLine(r esult);
wrt.Flush();
} catch (Exception e) {
Console.WriteLi ne(e.ToString() );
} finally {
if (rdr != null) rdr.Dispose();
if (skt != null) skt.Close();
}
C++ fragment :
char inbuf[1024];
iResult = recv(sock, inbuf, 1024, 0);
if (iResult != SOCKET_ERROR && iResult 0) {
Log::Debug(__WF ILE__, __LINE__, L"recvBuf has %d bytes\n", iResult);
if ( iResult 1024 ) {
Log::Debug(__WF ILE__, __LINE__, L"Received way too many bytes in
response - ignoring\n");
*netStatus = 6;
} else {
--- inbuf[iResult] = '\0';
::MultiByteToWi deChar(CP_ACP, 0, inbuf, iResult+1, outStr, 1024);
Log::Debug(__WF ILE__, __LINE__, L"Login response : %s\n", inbuf);
Log::Debug(__WF ILE__, __LINE__, L"Login response : %s\n", outStr);
*outBytes = wcslen(outStr); S
*netStatus = 0;
Log::Debug(__WF ILE__, __LINE__, L"<--SendServiceMess age received :
%s\n", outStr);
}
}
The socket communicatiopn works fine, but the problem is on the C++
end, if I check inbuf right after the socket read (i.e. at the --->),
it has an extra character in it.
Sent from C# : STATUS|£7.89 (GBP)|sess
Received by C++ : STATUS|£7.89 (GBP)|sess
Does anyone have any suggestions or theroies regarding the extra
character? I am stumped.
I am sending a string over a socket from a C# app to a native C++ app.
I embed the unicode symbol for the pound sign in the string being
sent. When I read data from the socket, I find that a 0xC2 has been
added into the input stream right before the pound symbol.
C# fragment :
TcpClient skt = null;
StreamWriter wrt = null;
try {
skt = local.AcceptTcp Client();
skt.NoDelay = true; //no buffering!
NetworkStream ns = skt.GetStream() ;
string result = "STATUS|\u00A37 .89 (GBP)|
sess"
wrt = new StreamWriter(ns );
//results are EOL delimited
wrt.WriteLine(r esult);
wrt.Flush();
} catch (Exception e) {
Console.WriteLi ne(e.ToString() );
} finally {
if (rdr != null) rdr.Dispose();
if (skt != null) skt.Close();
}
C++ fragment :
char inbuf[1024];
iResult = recv(sock, inbuf, 1024, 0);
if (iResult != SOCKET_ERROR && iResult 0) {
Log::Debug(__WF ILE__, __LINE__, L"recvBuf has %d bytes\n", iResult);
if ( iResult 1024 ) {
Log::Debug(__WF ILE__, __LINE__, L"Received way too many bytes in
response - ignoring\n");
*netStatus = 6;
} else {
--- inbuf[iResult] = '\0';
::MultiByteToWi deChar(CP_ACP, 0, inbuf, iResult+1, outStr, 1024);
Log::Debug(__WF ILE__, __LINE__, L"Login response : %s\n", inbuf);
Log::Debug(__WF ILE__, __LINE__, L"Login response : %s\n", outStr);
*outBytes = wcslen(outStr); S
*netStatus = 0;
Log::Debug(__WF ILE__, __LINE__, L"<--SendServiceMess age received :
%s\n", outStr);
}
}
The socket communicatiopn works fine, but the problem is on the C++
end, if I check inbuf right after the socket read (i.e. at the --->),
it has an extra character in it.
Sent from C# : STATUS|£7.89 (GBP)|sess
Received by C++ : STATUS|£7.89 (GBP)|sess
Does anyone have any suggestions or theroies regarding the extra
character? I am stumped.
Comment