public async Task <Client> create_and_open(bool enableRPCCompression) { TcpClient tcp_client = new TcpClient(this.host, this.port); TSIService.Client client; long sessionId, statementId; var transport = new TFramedTransport(new TSocketTransport(tcp_client, null)); if (!transport.IsOpen) { try{ await transport.OpenAsync(new CancellationToken()); } catch (TTransportException) { throw; } } if (enableRPCCompression) { client = new TSIService.Client(new TCompactProtocol(transport)); } else { client = new TSIService.Client(new TBinaryProtocol(transport)); } var open_req = new TSOpenSessionReq(protocol_version, zoneId); open_req.Username = username; open_req.Password = password; try{ var open_resp = await client.openSessionAsync(open_req); if (open_resp.ServerProtocolVersion != protocol_version) { var message = String.Format("Protocol Differ, Client version is {0} but Server version is {1}", protocol_version, open_resp.ServerProtocolVersion); throw new TException(message, null); } if (open_resp.ServerProtocolVersion == 0) { throw new TException("Protocol not supported", null); } sessionId = open_resp.SessionId; statementId = await client.requestStatementIdAsync(sessionId); } catch (Exception) { transport.Close(); throw; } is_close = false; var return_client = new Client(); return_client.client = client; return_client.sessionId = sessionId; return_client.statementId = statementId; return_client.transport = transport; return(return_client); }
public async static void startClient() { TTransport transport = null; try { string ip = "127.0.0.1"; string port = "6667"; string username = "******"; string password = "******"; // Make socket transport = new TSocketTransport(ip, int.Parse(port)); if (!transport.IsOpen) { await transport.OpenAsync(); } TProtocol protocol = new TCompactProtocol(transport); TSIService.Client client = new TSIService.Client(protocol); var result = await client.openSessionAsync(new TSOpenSessionReq() { Client_protocol = TSProtocolVersion.IOTDB_SERVICE_PROTOCOL_V2, Username = username, Password = password }); //await client.testInsertTabletAsync(new TSInsertTabletReq() //{ // DeviceId = "11", // Measurements = new System.Collections.Generic.List<string>() // { // "001" // }, // SessionId = result.SessionId, // Size = 10, // Timestamps =new byte[] { Convert.ToByte(DateTime.Now) }, // Values = new byte[] { Convert.ToByte(2.33d) } //}); Console.WriteLine("Thrift client result =: " + result.SessionId); } catch (Exception e) { Console.WriteLine(e.StackTrace); } finally { if (null != transport) { //close transport.Close(); } } }