I have a function that gets data from buffer and converts them to string as you can see :
public string GetParameters(byte[] buf)
{
string result = System.Text.UnicodeEncoding.Unicode.GetString(buf);
return result;
}
Another application sends a Farsi
string to buffer and my application should get this data, but my application's function returns this:
㨲께裙듘�����¯
How can i receive buffer data : I define this :
public byte[] dataBuffer = new byte[4000];
I have this function :
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)
{
}
}
And another one :
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);
}