本文整理汇总了C#中System.Net.Sockets.TcpClient.SendData方法的典型用法代码示例。如果您正苦于以下问题:C# TcpClient.SendData方法的具体用法?C# TcpClient.SendData怎么用?C# TcpClient.SendData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Sockets.TcpClient
的用法示例。
在下文中一共展示了TcpClient.SendData方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TcpClientConnectingToWrongIpAndThrowingOwnException
public void TcpClientConnectingToWrongIpAndThrowingOwnException()
{
var t = new Task(StartListeningV4);
t.Start();
try
{
var client = new TcpClient(
new IPEndPoint(new IPAddress(new byte[] {126, 0, 0, 1}), Port));
const string message = "to jest wiadomosc do przekazania";
var data = Encoding.UTF8.GetBytes(message);
var received = client.SendData(data);
}
catch (TimeoutException e)
{
EndConnection();
throw e;
}
catch (Exception)
{
EndConnection();
throw;
}
//throw new Exception();
}
示例2: TcpClientConnectingWithSpecifiedSocketAndReceivingAnswerIpV4
public void TcpClientConnectingWithSpecifiedSocketAndReceivingAnswerIpV4()
{
var client = new TcpClient(new IPEndPoint(_ipAddressv4, Port));
const string message = "to jest wiadomosc do przekazania";
var data = Encoding.UTF8.GetBytes(message);
var t = new Task(ListenAndResendV4);
t.Start();
var received = client.SendData(data);
Assert.AreEqual(data.Length, received.Length);
for (var i = 0; i < data.Length; ++i)
{
Assert.AreEqual(data[i], received[i]);
i++;
}
//check whether wait or dispose
EndConnection();
t.Wait();
}