首页

ThriftDemo实现客户端服务端通讯

c#

2020-9-28

支持多客户端发送通信给服务端

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Thrift.Protocol;
using Thrift.Transport;

namespace Client
{
    class Program
    {
 
        static void Main(string[] args)
        {
            try
            {
                //var transport = new TSocket("localhost", 15789);
                var protocol = new TBinaryProtocol(transport);
                var client = new Common.ChatService.Client(protocol);
                transport.Open();

                ////测试一
                //Task.Run(() =>
                //{
                //    while (true)
                //    {
                //        Random m = new Random();
                //        int ronum = m.Next(10000);
                //        string words = ronum "说" DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                //        string backMsg = ClientDo.GetServerData(words, client);
                //        Console.WriteLine(backMsg);
                //        Task.Delay(1000).Wait();
                //    }
                //});

                //测试二
                List<string> data = new List<string>();
                data.Add("每天吃饭");
                data.Add("每天看书");
                data.Add("每天跑步");
                List<string> list = client.GetList("小明", 66, data);
                Parallel.ForEach(list, m =>
                {
                    Console.WriteLine(m);
                });

                //transport.Close();

                Console.ReadKey();
            }
            catch (Exception ex)
            {
                Console.WriteLine("发送数据失败:" ex.Message);
            }
            Console.ReadLine();
        }
 
    }
}

资源下载此资源下载价格为3D币(VIP免费),请先
资源文件列表
ThriftTest/Client/Client/App.config , 189
ThriftTest/Client/Client/Client.csproj , 2821
ThriftTest/Client/Client/ClientDo.cs , 695
ThriftTest/Client/Client/Program.cs , 1486
ThriftTest/Client/Client/Properties/AssemblyInfo.cs , 1328
ThriftTest/Client/Client/packages.config , 142
ThriftTest/Common/Common/ChatService.cs , 31783
ThriftTest/Common/Common/Common.csproj , 2433
ThriftTest/Common/Common/Properties/AssemblyInfo.cs , 1319
ThriftTest/Common/Common/packages.config , 142
ThriftTest/ThriftTest/ThriftTest/App.config , 189
ThriftTest/ThriftTest/ThriftTest/Program.cs , 1319
ThriftTest/ThriftTest/ThriftTest/Properties/AssemblyInfo.cs , 1336
ThriftTest/ThriftTest/ThriftTest/TestServer.cs , 751
ThriftTest/ThriftTest/ThriftTest/ThriftServer.csproj , 2821
ThriftTest/ThriftTest/ThriftTest/demo-interface.thrift , 199
ThriftTest/ThriftTest/ThriftTest/gen-csharp/Common/ChatService.cs , 24156
ThriftTest/ThriftTest/ThriftTest/packages.config , 142
ThriftTest/ThriftTest/ThriftTest/thrift-0.11.0.exe , 2855936
ThriftTest/ThriftTest/ThriftTest.sln , 2097
ThriftTest/ThriftTest/packages/thrift-csharp.0.10.0/lib/Thrift.dll , 65536
ThriftTest/ThriftTest/packages/thrift-csharp.0.10.0/thrift-csharp.0.10.0.nupkg , 31680
没有账号? 忘记密码?

社交账号快速登录