static void Main(string[] args) { if (args.Length != 3 && args.Length != 1) { Console.WriteLine("Usage: Tunnel [<email> <password>] <device_id>"); Console.WriteLine("Example: Tunnel.exe streamdemo.nabto.net"); Console.WriteLine(" Default user is 'guest'."); Environment.Exit(1); } string email = "guest"; string password = ""; string deviceId; if (args[0].Contains("@")) { email = args[0]; password = args[1]; deviceId = args[2]; } else { deviceId = args[0]; } try { Console.WriteLine("Starting Nabto..."); NabtoClient nabto = new NabtoClient(); // Get a reference to the Nabto client runtime and start it up. Console.WriteLine("Creating session..."); using (Session session = nabto.CreateSession(email, password)) // Create a session using the specified user credentials. { Console.WriteLine("Creating tunnel..."); using (Nabto.Client.Tunneling.Tunnel tunnel = session.CreateTunnel(deviceId, 8080, "127.0.0.1", 80)) { while (Console.KeyAvailable == false) { Console.Write("Tunnel created - current state: {0}\r", tunnel.State); } Console.WriteLine(); Console.WriteLine("Shutting down..."); Console.ReadKey(true); } } } catch (Exception ex) { Console.WriteLine(ex); } }
public void initSocket() { Log.d(TAG, "initSocket()"); CloseSocket(); isWorking = false; NabtoClient nabto = new NabtoClient(); // Get a reference to the Nabto client runtime and start it up. var email = "guest"; var password = "******"; var threadStart = false; try { using (Session session = nabto.CreateSession(email, password)) // Create a session using the specified user credentials. { Console.WriteLine("Creating tunnel..."); using (Nabto.Client.Tunneling.Tunnel tunnel = session.CreateTunnel(_deviceId, 8080, "127.0.0.1", 80)) { //var device = session.CreateDeviceConnection(deviceId); //device. while (Console.KeyAvailable == false) { Console.Write("Tunnel created - current state: {0}\r", tunnel.State); var remoteRelayMicroState = Nabto.Client.Tunneling.TunnelState.RemoteRelayMicro; var RemotePeerToPeerState = Nabto.Client.Tunneling.TunnelState.RemotePeerToPeer; if (threadStart == false && (tunnel.State == remoteRelayMicroState || tunnel.State == RemotePeerToPeerState)) { SetSocket(ip, _devicePort); DoCommandStart(); DoCommandSecretCode(); var socketPrinterRunnable = new SocketPrinterRunnable(bThreadRunnig, socket); thread = new Thread(socketPrinterRunnable.run); thread.Start(); threadStart = true; int ccc = 1; while (ccc > 0) { int action = 0; Console.WriteLine("action:"); action = int.Parse(Console.ReadLine()); if (action == 1) { DoCommandTemp(); } else if (action == 2) { string attachment_file_name = "20180912072713"; byte[] array = Encoding.UTF8.GetBytes(attachment_file_name); int c = array.Length + 3; byte[] cmdSend = new byte[c]; cmdSend[0] = (byte)0xA5; cmdSend[1] = 0x06; for (int i = 0; i < array.Length; i++) { cmdSend[i + 2] = array[i]; } cmdSend[c - 1] = (byte)0xFF; Send(cmdSend); } else { DoSendPrint(); } Console.WriteLine("continue:"); ccc = int.Parse(Console.ReadLine()); } } } Console.WriteLine(); Console.WriteLine("Shutting down..."); Console.ReadKey(true); } } } catch (Exception e) { Log.d(TAG, e.Message); } //} }