Show / Hide Table of Contents

Connect to Thrift Server

Connect to Thrift Server with generated codes.

// Import Kift.ThriftGen.dll, Thrift.dll
using System;
using Thrift.Protocol;
using Thrift.Transport;

namespace Kift.Examples
{
    public class ConnectServer
    {
        public static void Main()
        {
            string host = "localhost";
            int port = 9090;

            TTransport transport = new TFramedTransport(new TSocket(host, port));
            TProtocol protocol = new TCompactProtocol(transport);
            KiftService.Client client = new KiftService.Client(protocol);
            transport.Open();
            Console.WriteLine("Server is connected!");

            // Call Kift API
            Vessel v = client.currentVessel();
            Console.WriteLine("Current vessel:" + v);

            transport.Close();
        }
    }
}
  • Improve this Doc
Back to top Copyright © 2019 Zhang Xiao