- //CLIENT
-
-
public void OnDataReceived(IAsyncResult asyn)
-
{
-
try
-
{
-
SocketPacket theSockId = (SocketPacket)asyn.AsyncState;
-
int iRx = theSockId.thisSocket.EndReceive(asyn);
-
char[] chars = new char[iRx + 1];
-
System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
-
int charLen = d.GetChars(theSockId.dataBuffer, 0, iRx, chars, 0);
-
System.String szData = new System.String(chars);
-
theSockId.message += szData;
-
if ((theSockId.message.Length > 0) && ((theSockId.message[0] != '<') ||
-
((theSockId.message[0] == '<') && (theSockId.message.IndexOf("</message>") > -1))))
-
{
-
DealWithResponse(theSockId);
-
}
-
else
-
WaitForData(theSockId);
-
}
-
catch (ObjectDisposedException)
-
{
-
System.Diagnostics.Debugger.Log(0, "1", "\nOnDataReceived: Socket has been closed\n");
-
}
-
catch (SocketException se)
-
{
-
MessageBox.Show(se.Message);
-
}
-
}
-
-
public void DealWithResponse(SocketPacket theSockId)
-
{
-
if (theSockId.message != null)
-
{
-
FileStream fileStream = File.Open(theSockId.theGame.KeyFile, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);
-
StreamWriter writer = new StreamWriter(fileStream);
-
writer.Write(theSockId.message);
-
writer.Close();
-
fileStream.Close();
-
}
-
}
-
Like I said before, this code works fine for text files. But it doesn't work for non-text files. What should I change to make it so that it works for both text and non-text files?
Let me know if you need more of the code. Thank you for taking your time to look at this.