私は、バッファからデータを取得し、あなたが見ることができるように文字列に変換する機能を持っている:C#でunicodeバッファバイトを取得すると '??????'
public string GetParameters(byte[] buf)
{
string result = System.Text.UnicodeEncoding.Unicode.GetString(buf);
return result;
}
別のアプリケーションがバッファするFarsi
文字列を送信し、私のアプリケーションは、このデータを取得する必要がありますが、自分のアプリケーションの機能は、これを返します:
㨲께裙듘�����¯
なぜですか?私はこの機能を持っている
public byte[] dataBuffer = new byte[4000];
: 私はこれを定義します。
public void WaitForData(System.Net.Sockets.Socket soc)
{
try
{
if (pfnWorkerCallBack == null)
{
// Specify the call back function which is to be
// invoked when there is any write activity by the
// connected client
pfnWorkerCallBack = new AsyncCallback(OnDataReceived);
}
SocketPacket theSocPkt = new SocketPacket();
theSocPkt.m_currentSocket = soc;
// Start receiving any data written by the connected client
// asynchronously
soc.BeginReceive(theSocPkt.dataBuffer, 0,
theSocPkt.dataBuffer.Length,
SocketFlags.None,
pfnWorkerCallBack,
theSocPkt);
}
catch (Exception qqq)
{
}
}
そしてもう一つ:
public void OnDataReceived(IAsyncResult asyn)
{
try
{
SocketPacket socketData = (SocketPacket)asyn.AsyncState;
int iRx = 0;
// Complete the BeginReceive() asynchronous call by EndReceive() method
// which will return the number of characters written to the stream
// by the client
iRx = socketData.m_currentSocket.EndReceive(asyn);
string res = GetParameters(socketData.dataBuffer);
}
「Unicode」ではなく「UTF32」を使用してください。 –
正確に4kバイトは、疑いなく丸められた数字です。 –
@ M.kazemAkhgary utf32はこれを返します: –