public ServerConnection()
        {
            try
            {
                TTransport transport = new TSocketTransport("localhost", 5000);

                TBinaryProtocol protocol = new TBinaryProtocol(transport);

                TMultiplexedProtocol multiplexedProtocolConsumer = new TMultiplexedProtocol(protocol, "ConsumerService");
                consumerService = new ConsumerService.Client(multiplexedProtocolConsumer);

                TMultiplexedProtocol multiplexedProtocolContentCreator = new TMultiplexedProtocol(protocol, "ContentCreatorService");
                contentCreatorService = new ContentCreatorService.Client(multiplexedProtocolContentCreator);

                TMultiplexedProtocol multiplexeProtocolAlbum = new TMultiplexedProtocol(protocol, "AlbumService");
                albumService = new AlbumService.Client(multiplexeProtocolAlbum);

                TMultiplexedProtocol multiplexeProtocolTrack = new TMultiplexedProtocol(protocol, "TrackService");
                trackService = new TrackService.Client(multiplexeProtocolTrack);

                TMultiplexedProtocol multiplexedProtocolPlaylist = new TMultiplexedProtocol(protocol, "PlaylistService");
                playlistService = new PlaylistService.Client(multiplexedProtocolPlaylist);

                TMultiplexedProtocol multiplexeProtocolLibrary = new TMultiplexedProtocol(protocol, "LibraryService");
                libraryService = new LibraryService.Client(multiplexeProtocolLibrary);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex + " in Session class");
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            var transport = new TSocket("localhost", 9090);
            var protocol  = new TBinaryProtocol(transport);
            var client    = new LibraryService.Client(protocol);

            transport.Open();

            var sw = new Stopwatch();

            sw.Start();
            var allBooks = client.GetAllBooks(); // Actual Thrift call

            sw.Stop();
            long elapsedMilliseconds = sw.ElapsedMilliseconds;
            // var firstBook = client.GetBook(allBooks.First().Id); // Actual Thrift call
        }
        private static void Main(string[] args)
        {
            var transport = new TSocket("localhost", 9090);
            var protocol  = new TBinaryProtocol(transport);
            var client    = new LibraryService.Client(protocol);

            transport.Timeout = 100;

            try
            {
                transport.Open();

                var allBooks = client.GetAllBooks(); // Thrift call

                Console.WriteLine("Total number of books: {0}\n", allBooks.Count);

                if (allBooks.Count > 0)
                {
                    Console.Write("Getting the first book: ");
                    var firstBook = client.GetBook(allBooks.First().Id); // Thrift call

                    Console.WriteLine("Id: {0}, {1} by {2}", firstBook.Id, firstBook.Title, firstBook.Author);
                }
            }
            catch (SocketException e)
            {
                Console.WriteLine("Could not connect to the server: {0}.", e.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine("An error occured: {0}", e.Message);
            }

            Console.WriteLine("\nDone. Press any key to continue...");
            Console.ReadKey(true);
        }