public static void Main(string[] args) { int port = 9090; for (int i = 0; i < args.Length; i++) { switch(args[i]) { case "--port": port = int.Parse(args[++i]); break; case "--help": Console.WriteLine("--port: Port used to connect with the server. (int)"); break; } } try { TSocket tSocket = new TSocket("localhost", port); tSocket.TcpClient.NoDelay = true; TTransport transport = tSocket; TProtocol protocol = new TBinaryProtocol(transport); Game.Client client = new Game.Client(protocol); transport.Open(); playGame(client); transport.Close(); } catch (TApplicationException x) { Console.WriteLine(x.StackTrace); } }
private static void Main() { TTransport framedTransport = new TFramedTransport(new TSocket("localhost", 9160)); TTransport socketTransport = new TSocket("localhost", 9160); TProtocol framedProtocol = new TBinaryProtocol(framedTransport); TProtocol socketProtocol = new TBinaryProtocol(socketTransport); var client = new Cassandra.Client(framedProtocol, framedProtocol); // all framed //var client = new Cassandra.Client(socketProtocol, socketProtocol); // all socket //var client = new Cassandra.Client(framedProtocol, socketProtocol); // in: framed out: socket //var client = new Cassandra.Client(socketProtocol, framedProtocol); // in: socket out: framed framedTransport.Open(); socketTransport.Open(); Console.WriteLine("Start"); client.set_keyspace("Keyspace1"); Console.WriteLine("Count Key"); var key = Encoding.ASCII.GetBytes("MyKey"); var columns = new List<byte[]>(new[] { Encoding.ASCII.GetBytes("MyColumn") }); var column_parent = new ColumnParent { Column_family = "Standard1" }; var predicate = new SlicePredicate { Column_names = columns }; client.get_count(key, column_parent, predicate, ConsistencyLevel.ALL); Console.WriteLine("Done"); Console.Read(); }
/// <summary> /// /// </summary> /// <param name="builder"></param> internal Connection(Server server, ConnectionBuilder builder) { Created = DateTime.Now; Server = server; var socket = new TSocket(server.Host, server.Port, server.Timeout * 1000); switch(builder.ConnectionType) { case ConnectionType.Simple: _transport = socket; break; case ConnectionType.Buffered: _transport = new TBufferedTransport(socket, builder.BufferSize); break; case ConnectionType.Framed: _transport = new TFramedTransport(socket); break; } _protocol = new TBinaryProtocol(_transport); _client = new Cassandra.Client(_protocol); }
public CassandraClient Create(CassandraEndpoint endpoint) { TSocket socket = null; TTransport transport = null; if (endpoint.Timeout == 0) { socket = new TSocket(endpoint.Address, endpoint.Port); } else { socket = new TSocket(endpoint.Address, endpoint.Port, endpoint.Timeout); } if (this.isBufferSizeSet) { transport = new TBufferedTransport(socket, this.bufferSize); } else { transport = new TBufferedTransport(socket); } TProtocol protocol = new TBinaryProtocol(transport); Cassandra.Client cassandraClient = new Cassandra.Client(protocol); CassandraClient client = new CassandraClient(cassandraClient, endpoint); this.logger.Debug(logger.StringFormatInvariantCulture("Created a new connection using: '{0}'", endpoint.ToString())); return client; }
public static void Main() { try { TTransport transport = new TSocket("localhost", 9090); TProtocol protocol = new TBinaryProtocol(transport); Calculator.Client client = new Calculator.Client(protocol); transport.Open(); try { client.ping(); Console.WriteLine("ping()"); int sum = client.add(1, 1); Console.WriteLine("1+1={0}", sum); Work work = new Work(); work.Op = Operation.DIVIDE; work.Num1 = 1; work.Num2 = 0; try { int quotient = client.calculate(1, work); Console.WriteLine("Whoa we can divide by 0"); } catch (InvalidOperation io) { Console.WriteLine("Invalid operation: " + io.Why); } work.Op = Operation.SUBTRACT; work.Num1 = 15; work.Num2 = 10; try { int diff = client.calculate(1, work); Console.WriteLine("15-10={0}", diff); } catch (InvalidOperation io) { Console.WriteLine("Invalid operation: " + io.Why); } SharedStruct log = client.getStruct(1); Console.WriteLine("Check log: {0}", log.Value); } finally { transport.Close(); } } catch (TApplicationException x) { Console.WriteLine(x.StackTrace); } }
public void GetHBaseImage(string rowKey = "20150822180801118") { var socket = new TSocket(hbaseThrif, hbaseThrifPort); var transport = new TBufferedTransport(socket); var protocol = new TBinaryProtocol(transport); Hbase.Client hbaseClient = new Hbase.Client(protocol); transport.Open(); //List<byte[]> tableNames = hc.getTableNames(); byte[] table = Encoding.UTF8.GetBytes("FiservImages"); byte[] row = Encoding.UTF8.GetBytes(rowKey); byte[] column = Encoding.UTF8.GetBytes("ImageData:Image"); List<TRowResult> results = hbaseClient.getRow(table, row, null); TCell t = new TCell(); //t. foreach (TRowResult result in results) { //result.Columns[column] //result.Columns; Dictionary<byte[], TCell> konj; konj = result.Columns; //string s = Encoding.UTF8.GetString(result.Columns[column].Value); foreach (KeyValuePair<byte[], TCell> singleRow in konj) { //File.WriteAllBytes(@"c:\test\output.docx", singleRow.Value.Value); OpenFile(singleRow.Value.Value, "output.docx"); } } }
//获取连接 public ThriftHadoopFileSystem.Client Connect(out TBufferedTransport tsport) { if (HostServer == null) { throw new ArgumentNullException("HostServer"); } if (Port == 0) { throw new ArgumentNullException("Port"); } TSocket hadoop_socket = new TSocket(HostServer, Port); //hadoop_socket.Timeout = 10000;// Ten seconds tsport = new TBufferedTransport(hadoop_socket); TBinaryProtocol hadoop_protocol = new TBinaryProtocol(tsport, false, false); ThriftHadoopFileSystem.Client client = new ThriftHadoopFileSystem.Client(hadoop_protocol); try { tsport.Open(); return client; } catch (Exception ex) { //throw (new Exception("打开连接失败!", ex)); tsport = null; return null; } }
public IClient Create(IEndpoint endpoint, IClientPool ownerPool) { TSocket socket = null; TTransport transport = null; if (endpoint.Timeout == 0) { socket = new TSocket(endpoint.Address, endpoint.Port); } else { socket = new TSocket(endpoint.Address, endpoint.Port, endpoint.Timeout); } TcpClient tcpClient = socket.TcpClient; if (this.isBufferSizeSet) { transport = new TBufferedTransport(socket, this.bufferSize); } else { transport = new TBufferedTransport(socket); } TProtocol protocol = new TBinaryProtocol(transport); CassandraClient cassandraClient = new CassandraClient(protocol); IClient client = new DefaultClient() { CassandraClient = cassandraClient, Endpoint = endpoint, OwnerPool = ownerPool, TcpClient = tcpClient, Created = DateTime.Now }; return client; }
public Apache.Cassandra.Cassandra.Iface CreateConnection(String host, Int32 port) { TSocket socket = new TSocket(host, port); TTransport trans = new TFramedTransport(socket); trans.Open(); return new Apache.Cassandra.Cassandra.Client(new TBinaryProtocol(trans)); }
static void Main(string[] args) { // Initialize log4net l4n.Config.XmlConfigurator.Configure(); // Create log var log = new LogEntry(); log.Category = "Program"; log.Message = "This is a test error message from the program"; // Connect var socket = new TSocket("192.168.1.144",65510,300); var transport = new TFramedTransport(socket); var protocol = new TBinaryProtocol(transport,false,false); var scribeClient = new scribe.Client(protocol); transport.Open(); // Send var logs = new List<LogEntry>(); logs.Add(log); var result = scribeClient.Log(logs); // Close transport.Close(); // use log4net to log var logger = l4n.LogManager.GetLogger("ScribeAppender.Test.Program"); logger.Debug("This is a test error message from the logger"); }
public IClient Create(IEndpoint endpoint, IClientPool ownerPool) { TSocket socket = null; if (endpoint.Timeout == 0) { socket = new TSocket(endpoint.Address, endpoint.Port); } else { socket = new TSocket(endpoint.Address, endpoint.Port, endpoint.Timeout); } TcpClient tcpClient = socket.TcpClient; TProtocol protocol = new TBinaryProtocol(socket); CassandraClient cassandraClient = new CassandraClient(protocol); IClient client = new DefaultClient() { CassandraClient = cassandraClient, Endpoint = endpoint, OwnerPool = ownerPool, TcpClient = tcpClient, Created = DateTime.Now }; return client; }
public int Run() { int c = 0; try { TTransport transport = new TSocket(Host, Port); TProtocol protocol = new TBinaryProtocol(transport); var client = new MultiplicationService.Client(protocol); Console.WriteLine("Thrift client opening transport to {0} on port {1} ...", Host, Port); transport.Open(); int a, b; Console.Write("Enter 1st integer : "); int.TryParse(Console.ReadLine(), out a); Console.Write("Enter 2nd integer : "); int.TryParse(Console.ReadLine(), out b); c = client.multiply(a, b); Console.WriteLine("{0} x {1} = {2}", a, b, c); Console.WriteLine("Thrift client closing transport ..."); transport.Close(); } catch (TApplicationException x) { Console.WriteLine(x.StackTrace); } return c; }
static void Main(string[] args) { MessageObject mo1 = new MessageObject{TimeStamp = DateTime.Now, Message="begin process...."}; LogHelper.WriteLogInfo(typeof(Program), mo1); TTransport transport = new TSocket("localhost", 7911); TProtocol protocol = new TBinaryProtocol(transport); ThriftCase.Client client = new ThriftCase.Client(protocol); transport.Open(); Console.WriteLine("Client calls ....."); map.Add("blog", "http://www.javabloger.com"); client.testCase1(10, 21, "3"); client.testCase2(map); client.testCase3(); Blog blog = new Blog(); //blog.setContent("this is blog content".getBytes()); blog.CreatedTime = DateTime.Now.Ticks; blog.Id = "123456"; blog.IpAddress = "127.0.0.1"; blog.Topic = "this is blog topic"; blogs.Add(blog); client.testCase4(blogs); transport.Close(); //LogHelper.WriteLog(typeof(Program), "end process......"); Console.ReadKey(); }
/// <summary> /// /// </summary> private void InitTransportAndClient() { var socket = new TSocket(Server.Host, Server.Port, Server.Timeout * 1000); switch (ConnectionType) { case ConnectionType.Simple: _transport = socket; break; case ConnectionType.Buffered: _transport = new TBufferedTransport(socket, BufferSize); break; case ConnectionType.Framed: _transport = new TFramedTransport(socket); break; default: goto case ConnectionType.Framed; } var protocol = new TBinaryProtocol(_transport); _client = new Cassandra.Client(protocol); }
static void Main(string[] args) { //�������ݿ����� TTransport transport = new TSocket("192.168.10.2", 9160); TProtocol protocol = new TBinaryProtocol(transport); Cassandra.Client client = new Cassandra.Client(protocol); transport.Open(); System.Text.Encoding utf8Encoding = System.Text.Encoding.UTF8; long timeStamp = DateTime.Now.Millisecond; ColumnPath nameColumnPath = new ColumnPath() { Column_family = "Standard1", Column = utf8Encoding.GetBytes("age") }; //д������ client.insert("Keyspace1", "studentA", nameColumnPath, utf8Encoding.GetBytes("18"), timeStamp, ConsistencyLevel.ONE); //��ȡ���� ColumnOrSuperColumn returnedColumn = client.get("Keyspace1", "studentA", nameColumnPath, ConsistencyLevel.ONE); Console.WriteLine("Keyspace1/Standard1: age: {0}, value: {1}", utf8Encoding.GetString(returnedColumn.Column.Name), utf8Encoding.GetString(returnedColumn.Column.Value)); //�ر����� transport.Close(); }
internal ThriftMessageSender(Uri serviceUri) { socket = new TSocket(serviceUri.Host, serviceUri.Port); transport = new TBufferedTransport(socket); transport.Open(); client = new MessageService.Client(new TCompactProtocol(transport)); }
public void Setup() { var socket = new TSocket(host, port); transport = new TFramedTransport(socket); var protocol = new TBinaryProtocol(transport); Client = new ZipkinCollector.Client(protocol); transport.Open(); }
/// <summary> /// /// </summary> public ThriftConnection(IConnectionSettings connectionSettings) { Created = DateTime.Now; var tsocket = new TSocket(connectionSettings.Host, connectionSettings.Port); _transport = new TBufferedTransport(tsocket, 1024); _protocol = new TBinaryProtocol(_transport); _client = new Rest.Client(_protocol); }
public LegacyThriftClient(string host, int port) { if (host == null) throw new ArgumentNullException("host"); _transport = new TSocket(host, port); TProtocol protocol = new TBinaryProtocol(_transport); _client = new ThriftFlumeEventServer.Client(protocol); _transport.Open(); }
static void StartClient(string userName) { TTransport transport = new TSocket("localhost", 12000); TProtocol protocol = new TBinaryProtocol(transport); transport.Open(); }
public HClient() { socket = new TSocket(host, port); this.Transport = new TBufferedTransport(socket); //Transport.Open(); this.protocol = new TBinaryProtocol(Transport); this.Client = new Apache.Hadoop.Hbase.Hbase.Client(protocol); this.IsFree = true; }
static void Main(string[] args) { TTransport trans = new TSocket("localhost", 8585); trans = new TBufferedTransport(trans as TStreamTransport); trans.Open(); TBinaryProtocol proto = new TBinaryProtocol(trans); helloSvc.Client client = new helloSvc.Client(proto); string result = client.getMessage("Ginger"); Console.WriteLine("Received from server: " + result); }
static void Main(string[] args) { TTransport transport = new TSocket("localhost", 1337); TProtocol proto = new TBinaryProtocol(transport); TimeService.Client client = new TimeService.Client(proto); transport.Open(); Console.WriteLine(client.GetTime()); Console.ReadKey(); }
/// <summary> /// /// </summary> /// <param name="builder"></param> internal Connection(Server server) { Created = DateTime.Now; Server = server; TTransport socket = new TSocket(server.Host, server.Port, server.Timeout); _transport = new TFramedTransport(socket); _protocol = new TBinaryProtocol(_transport); _client = new Cassandra.Client(_protocol); }
static void Main(string[] args) { var transport = new TSocket("localhost", 7911); var protocol = new TBinaryProtocol(transport); var client = new UserStorage.Client(protocol); transport.Open(); var userdata = new UserProfile(); userdata.Name = "Jeske"; client.store(userdata); transport.Close(); }
protected virtual void Dispose(bool disposing) { if (!_disposed) { if (disposing) { _transport.Close(); _transport.Dispose(); _transport = null; } } _disposed = true; }
public static void test() { var hadoop_socket = new TSocket("hserver", 59256); hadoop_socket.Timeout = 10000;// Ten seconds //$hadoop_socket -> setRecvTimeout(20000); // Twenty seconds var hadoop_transport = new TBufferedTransport(hadoop_socket); var hadoop_protocol = new TBinaryProtocol(hadoop_transport); var hadoopClient = new ThriftHadoopFileSystem.Client(hadoop_protocol); hadoop_transport.Open(); //if (hadoopClient.exists(new Pathname { pathname = "/user/root/input" })) //{ // System.Console.WriteLine("exists"); //} //else //{ // Console.WriteLine("no exists"); //} //hadoopClient.mkdirs(new Pathname { pathname = "/zbw911_user" }); //hadoopClient.rm(new Pathname { pathname = "/zbw911_user" }, true); //var h = hadoopClient.createFile(new Pathname { pathname = "user_zbw911" }, 1, true, 1000, 1, 64000); var list = hadoopClient.listStatus(new Pathname { pathname = "/user/root" }); foreach (var item in list) { System.Console.WriteLine(item); //if (item.Isdir) //{ // System.Console.WriteLine("文件夹:" + item.Path + ";权限:" + item.Permission); //} //else //{ // System.Console.WriteLine("文件:" + item.Path + ";权限:" + item.Permission); //} } //hadoopClient.close(h); //hadoopClient.open(new Pathname { pathname = "/user/root" }); hadoop_transport.Close(); }
static void Main(string[] args) { TTransport transport = new TSocket("localhost", 9090); TProtocol protocol = new TBinaryProtocol(transport); ConvertSvc.Client client= new ConvertSvc.Client(protocol); transport.Open(); var units = String.Join(", ", client.availableUnits_func().Select(s => s)); Console.WriteLine("Please enter lengths to convert in format '<length> <unit> in <unit>', using {0}", units); while (true) { var input = Console.ReadLine(); var output = client.convert_func(input); Console.WriteLine(output); } }
public ThriftConnection(IConnectionSettings connectionSettings) { this._timeout = connectionSettings.Timeout; this._poolSize = connectionSettings.MaximumAsyncConnections; this._resourceLock = new Semaphore(_poolSize, _poolSize); for (var i = 0; i <= connectionSettings.MaximumAsyncConnections; i++) { var tsocket = new TSocket(connectionSettings.Host, connectionSettings.Port); var transport = new TBufferedTransport(tsocket, 1024); var protocol = new TBinaryProtocol(transport); var client = new Rest.Client(protocol); _clients.Enqueue(client); } }
private static bool CheckCassandraIsRunning() { TTransport transport = new TSocket("localhost", 9160); TProtocol protocol = new TBinaryProtocol(transport); Cassandra.Client client = new Cassandra.Client(protocol); try { transport.Open(); success = true; } catch { success = false; } return success; }
/// <summary> /// 推送比对记录 /// </summary> /// <param name="info"></param> /// <param name="IP"></param> /// <returns></returns> public int UpdateCmp(RealtimeCmpInfo info, string IP) { try { // 生成socket套接字; Thrift.Transport.TSocket tsocket = new Thrift.Transport.TSocket(IP, 6000); //设置连接超时为100; tsocket.Timeout = 3000; //生成客户端对象 Thrift.Transport.TTransport transport = tsocket; Thrift.Protocol.TProtocol protocol = new Thrift.Protocol.TBinaryProtocol(transport); UIServer.Client _BusinessServerClient = new UIServer.Client(protocol); transport.Open(); _BusinessServerClient.UpdateRealtimeCmp(info, "##@" + info.Channel); transport.Close(); return(0); } catch (Exception ex) { _WriteLog.WriteToLog("UpdateCmp", ex); return(-1); } }
public TSaslClientTransport(TSocket socket, string userName, string password) { _sasl = new SASLClient(socket.Host, new PlainMechanism(userName, password)); _socket = socket; }
public void Dispose() { _socket.Close(); _socket = null; _sasl.Dispose(); }