本文整理汇总了C#中NetworkStream.EndWrite方法的典型用法代码示例。如果您正苦于以下问题:C# NetworkStream.EndWrite方法的具体用法?C# NetworkStream.EndWrite怎么用?C# NetworkStream.EndWrite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetworkStream
的用法示例。
在下文中一共展示了NetworkStream.EndWrite方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: sendNetMessage
/// <summary>
/// Envia un mensaje a la red mediante esta maquina remota
/// </summary>
/// <param name="netMessage">el mensaje a enviar</param>
/// <param name="timeOutWriteTCP">el tiempo maximo de espera para el envio</param>
public void sendNetMessage(NetMessage netMessage, Int32 timeOutWriteTCP)
{
lock (sendTCPLock)
{
Fails++;
senderStream = new NetworkStream(TcpClient.Client, false);
try
{
//senderStream.WriteTimeout = timeOutWriteTCP;
byte[] lenght = BitConverter.GetBytes(netMessage.getSize());
byte[] netByteMessage = new byte[4 + netMessage.getSize()];
IAsyncResult result = senderStream.BeginWrite(lenght, 0, 4, null, null);
bool success = result.AsyncWaitHandle.WaitOne(timeOutWriteTCP, false);
if (!success)
{
throw new Exception("TCP: intento de conexión ha tardado demasiado");
}
else
{
senderStream.EndWrite(result);
}
result = senderStream.BeginWrite(netMessage.Body, 0, netMessage.getSize(), null, null);
success = result.AsyncWaitHandle.WaitOne(timeOutWriteTCP, false);
if (!success)
{
throw new Exception("TCP: intento de conexión ha tardado demasiado");
}
else
{
senderStream.EndWrite(result);
}
senderStream.Close();
Fails = 0;
}
catch (ThreadAbortException e)
{
try
{
senderStream.Close();
}
catch (Exception)
{
}
throw e;
}
catch (Exception)
{
try
{
senderStream.Close();
}
catch (Exception)
{
}
throw;
}
}
}