当前位置: 首页>>代码示例>>C#>>正文


C# Service.Listen方法代码示例

本文整理汇总了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();
        }
    }
开发者ID:lailongwei,项目名称:llbc,代码行数:46,代码来源:TestCase_Comm_Service.cs

示例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();
        }
    }
开发者ID:lailongwei,项目名称:llbc,代码行数:25,代码来源:TestCase_Comm_Service.cs

示例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();
        }
    }
开发者ID:lailongwei,项目名称:llbc,代码行数:20,代码来源:TestCase_Comm_Service.cs


注:本文中的Service.Listen方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。