コード例 #1
0
ファイル: ProfilerClient.cs プロジェクト: corefan/brofiler
    public bool SendMessage(Message message)
    {
			try
			{
				CheckConnection();

				lock (criticalSection)
				{
					MemoryStream buffer = new MemoryStream();
					message.Write(new BinaryWriter(buffer));
					buffer.Flush();

					UInt32 length = (UInt32)buffer.Length;

					NetworkStream stream = client.GetStream();

					BinaryWriter writer = new BinaryWriter(stream);
					writer.Write(Message.MESSAGE_MARK);
					writer.Write(length);

					buffer.WriteTo(stream);
					stream.Flush();
				}

				return true;
			}
			catch (Exception ex)
			{
				if (MessageBox.Show(ex.Message) == MessageBoxResult.OK)
				{
					lock (criticalSection)
					{
						//client.Client.Shutdown(SocketShutdown.Both);
						client = new TcpClient();
					}
				}
			}

			return false;
    }