本文整理汇总了C#中Service.Listen方法的典型用法代码示例。如果您正苦于以下问题:C# Service.Listen方法的具体用法?C# Service.Listen怎么用?C# Service.Listen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Service
的用法示例。
在下文中一共展示了Service.Listen方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: _SendRecvTest
private void _SendRecvTest()
{
Console.WriteLine("Send/Recv test:");
using (Service svc = new Service("SendRecvTest"))
{
svc.Start();
IPEndPoint ep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 7788);
int listenSessionId = svc.Listen(ep);
Console.WriteLine("Listened on [{0}], sessionId: {1}", ep, listenSessionId);
int connSessionId = svc.Connect(ep);
Console.WriteLine("Connected to {0}, sessionId: {1}", ep, connSessionId);
// Test Send
TestPacket data = new TestPacket();
data.intVal = 10086;
data.strVal = "Hello World";
svc.Send(connSessionId, data);
// Test Multicast
TestMulticastPacket multicastData = new TestMulticastPacket();
multicastData.intVal = 10010;
multicastData.strVal = "Multicast data";
List<int> multicastSessionIds = new List<int>();
multicastSessionIds.Add(connSessionId);
svc.Multicast(multicastSessionIds, multicastData);
// Test Broadcast
TestBroadcastPacket broadcastData = new TestBroadcastPacket();
broadcastData.intVal = 8888;
broadcastData.strVal = "Broadcast data";
svc.Broadcast(broadcastData);
// Test unhandled packet
svc.Send(connSessionId, new UnHandledPacket());
// Test coder not found
MemoryStream unhandledStream = new MemoryStream();
unhandledStream.Write(new byte[30], 0, 30);
svc.Send(connSessionId, 10086, unhandledStream);
Console.WriteLine("Press any key to exit Send/Recv test...");
Console.ReadKey();
}
}
示例2: _ConnectTest
private void _ConnectTest()
{
Console.WriteLine("Connect test:");
using (Service svc = new Service("ConnectTest"))
{
svc.Start();
IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 7788);
// Listen
int listenSessionId = svc.Listen(endPoint);
Console.WriteLine("Listened on {0}, sessionId: {1}", endPoint, listenSessionId);
// Synchronous connect.
int connSessionId = svc.Connect(endPoint);
Console.WriteLine("Connected to {0}, sessionId: {1}", endPoint, connSessionId);
// Asynchronous connect.
svc.AsyncConn(endPoint);
// Error endpoint's asynchronous connect.
svc.AsyncConn(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 7789));
Console.WriteLine("Press any key to exit connect test...");
Console.ReadKey();
}
}
示例3: _ListenTest
private void _ListenTest()
{
Console.WriteLine("Listen test:");
using (Service svc = new Service("ListenTest"))
{
svc.Start();
IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 7788);
int sessionId = svc.Listen(endPoint);
Console.WriteLine("Listened on {0}, sessionId: {1}", endPoint, sessionId);
Console.WriteLine("Remove listen session: {0}", sessionId);
svc.RemoveSession(sessionId, "Listen test remove", true);
Console.WriteLine("Press any key to exit listen test...");
Console.ReadKey();
}
}