Пример #1
0
        async public void Communicate()
        {
            using (var communicator = new Communicator(this.ip, this.port, this.password, this.key, this.iv))
            {
                var clipbText = await Clipboard.GetTextAsync();

                this.StatusHTML = "<p>Sending...</p>";
                var success = true;
                try
                {
                    await Task.Run(() =>
                    {
                        communicator.Connect();
                        communicator.SendText(clipbText);
                    });
                }
                catch (System.Net.Sockets.SocketException ex)
                {
                    success         = false;
                    this.StatusHTML = $"<p style=\"color:red\">{ex.Message}</p>";
                }

                if (success)
                {
                    this.StatusHTML = "<p style=\"color:green\">Finished.</p>";
                }
            }
        }
Пример #2
0
        async public void Communicate()
        {
            using var communicator = new Communicator(this.ip, this.port, this.password, this.key, this.iv);

            var picked = await FilePicker.PickAsync();

            var fileName = picked.FileName;
            var inStream = await picked.OpenReadAsync();

            this.StatusHTML = "<p>Sending...</p>";
            var success = true;

            try
            {
                await Task.Run(() =>
                {
                    communicator.Connect();
                    communicator.SendStream(inStream, fileName);
                });
            }
            catch (System.Net.Sockets.SocketException ex)
            {
                success         = false;
                this.StatusHTML = $"<p style=\"color:red\">{ex.Message}</p>";
            }

            if (success)
            {
                this.StatusHTML = "<p style=\"color:green\">Finished.</p>";
            }
        }
Пример #3
0
        public void Connect()
        {
            _device = _communicator.Search(_settings.Name);
            _communicator.Connect(_device.SerialPort);

            _timer.Start();
        }
Пример #4
0
        private void ListenForMessages()
        {
            Task.Run(() =>
            {
                using (var cc = new Communicator(StreamVRApp.Instance.NatsServerURL, this.UserName, this.RoomCode, _log))
                {
                    cc.Connect();
                    cc.Subscribe(cc.TO_SERVER_CHANNEL, (Message msg) =>
                    {
                        msgQueue.Enqueue(msg);
                    });

                    bool _shutdown = false;
                    while (!_shutdown)
                    {
                        if (msgQueue.Count > 0)
                        {
                            Message msg = msgQueue.Dequeue();

                            _log("[STREAMVR] Next msg");
                            _log(JsonConvert.SerializeObject(msg));

                            if (msg.Reply != null)
                            {
                                StreamVRApp.Instance.CurrentRequest = msg;

                                _exEvent.Raise();

                                while (StreamVRApp.Instance.CurrentResponse == null)
                                {
                                    Thread.Sleep(50);
                                }

                                Message response = StreamVRApp.Instance.CurrentResponse;

                                if (response.Type == "ERROR")
                                {
                                    _log($"[STREAMVR] Error response");
                                    _log(JsonConvert.SerializeObject(response));
                                }

                                _log($"[STREAMVR] Replying to request");

                                response.Reply = msg.Reply;
                                cc.Publish(msg.Reply, response);

                                StreamVRApp.Instance.CurrentResponse = null;
                            }
                            else if (msg.Type == "EXIT")
                            {
                                _log("Exit command received");
                                _shutdown = true;
                            }
                        }
                        Thread.Sleep(100);
                    }
                }
            });
        }
Пример #5
0
 public void TextSubmitted()
 {
     if (Network.peerType == NetworkPeerType.Disconnected)
     {
         string connectionIP = ((UnityEngine.UI.InputField)textInput).text;
         communicator.Connect(connectionIP);
     }
 }
Пример #6
0
        public static void ShutdownInterface()
        {
            var comms = new Communicator("streamvr.lm2.me:4222", "lisamarie.mueller", "123456", Debug.Log);

            comms.Connect();
            comms.Publish(comms.TO_SERVER_CHANNEL, new Message {
                Type = "EXIT"
            });
        }
Пример #7
0
        public static void ExportAllMaterials()
        {
            var comms = new Communicator("streamvr.lm2.me:4222", "lisamarie.mueller", "123456", Debug.Log);

            comms.Connect();
            Message response = comms.RequestSync(comms.TO_SERVER_CHANNEL, new Message {
                Type = "EXPORT_ALL_MATERIALS"
            }, 30000);

            Debug.Log(JsonConvert.SerializeObject(response));
        }
Пример #8
0
        public async Task ConnectsToServer()
        {
            // When
            var communicator = new Communicator("localhost", _port);

            communicator.Connect();
            var communicatorSeenFromServer = await _acceptTask;

            // Then
            Assert.That(communicatorSeenFromServer.Connected);
        }
Пример #9
0
        private async void RunCommunicationInTaskAsync(CancellationToken token, int delay, int workerId)
        {
            Communicator comm  = null;
            int          sleep = Math.Max(delay - 10, 10);

            try
            {
                comm = new Communicator(txtIpdAddress.Text, 11000, workerId);

                await comm.Connect();

                for (int i = 0; i < 2000; i++)
                {
                    var  timer     = Task.Delay(sleep, token).ConfigureAwait(false);
                    bool isWorking = await comm.ReadData(token).ConfigureAwait(false);

                    if (!isWorking)
                    {
                        comm.IsWorking = false;
                        break;
                    }
                    await timer;
                }

                //TODO !comm.IsWorkint restart ....
            }
            catch (Exception e)
            {
                Di.Trace.WriteLine(e);
            }
            finally
            {
                lock (_lock)
                {
                    _taskCouter--;
                    if (_taskCouter == 0)
                    {
                        _watch.Stop();
                        var elapsedMs = _watch.ElapsedMilliseconds;
                        Di.Trace.WriteLine(string.Format("{0} Finished test. Worker type: {1}, workers count: {2}, clientType: {3}", DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.fff"), "Pure Async", 64, "Async TcpClient"));
                        Di.Trace.WriteLine(string.Format("Duration {0}", elapsedMs));
                    }
                }

                if (comm != null)
                {
                    await comm.Close().ConfigureAwait(false);
                }
            }
        }
Пример #10
0
        public static ICommunicator Connect()
        {
            ICommunicator comms = new Communicator(BusConnector.natsEndpoint, BusConnector.username, BusConnector.roomCode, Debug.Log);

            Debug.Log("Connecting...");

            comms.Connect();

            Debug.Log("Connected");

            Debug.Log($"> {natsEndpoint}");
            Debug.Log($"> {username}");
            Debug.Log($"> {roomCode}");

            return(comms);
        }
Пример #11
0
        public void Connect()
        {
            communicator = new Communicator();

            string clientName = String.Format("{0}_client",
                                              robotName == null ? "control" : robotName);

            if (communicator.Connect(hostname, port, clientName) < 0)
            {
                log.Fatal("Cannot connect to RoBOSS Controller. Exiting.");
                communicator.Dispose();
                Environment.Exit(1);
            }
            log.Info("Connected to RoBOSS Controller.");

            SendAck();
        }
Пример #12
0
        public void connect(String ipAddr, String port)
        {
            lock (this)
            {
                if (!IsConnected)
                {
                    communicator = new Communicator();
                    if (communicator.Connect(ipAddr, port, TestController.robossClientName) < 0)
                    {
                        string msg = "Unable to connect RoboSS controller " + ipAddr + ":" + port;
                        LOG.Debug(msg);
                        communicator = null;
                        throw new CommunicatorException(msg);
                    }
                    LOG.Info("Connected to RoboSS controller " + ipAddr + ":" + port);
                    IsConnected = true;

                }
            }
        }
Пример #13
0
    public override void Init()
    {
        base.Init();
        communicator = new Communicator();
        Parameters paramerters = new Parameters();

        paramerters.epsilon = epsilon;
        paramerters.gamma   = gamma;
        paramerters.alpha   = alpha;
        paramerters.states  = new List <int>();
        for (int i = 0; i < 9; i++)
        {
            for (int j = 0; j < 5; j++)
            {
                paramerters.states.Add(i + 10 * j);
            }
        }
        string envMessage = JsonConvert.SerializeObject(paramerters, Formatting.Indented);

        communicator.Connect(envMessage, OnRecv);
        Debug.Log("****   socket is init   ****");
    }
Пример #14
0
        public async Task ReceivesMessageFromServer()
        {
            // Give
            var message    = "testMessage";
            var buffer     = System.Text.Encoding.UTF8.GetBytes(message);
            var messageLen = BitConverter.GetBytes(IPAddress.HostToNetworkOrder((Int32)buffer.Length));

            var communicator = new Communicator("localhost", _port);

            communicator.Connect();
            var communicatorSeenFromServer = await _acceptTask;
            var stream = communicatorSeenFromServer.GetStream();

            stream.Write(messageLen, 0, 4);
            stream.Write(buffer, 0, buffer.Length);

            // When
            var result = communicator.Receive();

            // Then
            Assert.That(String.Equals(message, result));
        }
Пример #15
0
        private void ListenForMessages(UIDocument uiDoc)
        {
            using (var cc = new Communicator(this.serverUrl, this.userName, this.roomCode, this.Debug))
            {
                cc.Connect();
                cc.Subscribe(cc.TO_SERVER_CHANNEL, (Message msg) =>
                {
                    msgQueue.Enqueue(msg);
                });

                bool _shutdown = false;
                while (!_shutdown)
                {
                    if (msgQueue.Count > 0)
                    {
                        Message msg = msgQueue.Dequeue();

                        Debug(JsonConvert.SerializeObject(msg));

                        if (msg.Reply != null)
                        {
                            Message response = HandleClientRequest(uiDoc.Document, msg);
                            response.Reply = msg.Reply;
                            cc.Publish(msg.Reply, response);
                        }
                        else if (msg.Type == "EXIT")
                        {
                            Debug("Exit command received");
                            _shutdown = true;
                        }
                    }

                    uiDoc.RefreshActiveView();
                    Thread.Sleep(200);
                }
            }
        }
Пример #16
0
        static void Main(string[] args)
        {
            var options = new Options();

            if (!Parser.Default.ParseArguments(args, options))
            {
                return;
            }

            var settings = new Settings
            {
                Name                  = options.Name,
                DontBlock             = options.Block,
                PathFinderGiveUpLimit = options.TickAdjust * 9,
                FillGiveUpLimit       = options.TickAdjust * 4
            };

            var converter    = new ManualStreamToMessageConverter();
            var communicator = new Communicator(options.Address, options.Port, converter);
            var gameClient   = new GameClient(communicator, settings);

            try
            {
                communicator.Connect();
                gameClient.StartGame();
            }
            catch (Exception e)
            {
                System.Console.WriteLine("Exception: " + e.Message);
            }
            finally
            {
                System.Console.Read();
                communicator.Dispose();
            }
        }
Пример #17
0
        public async Task SendsMessageToServer()
        {
            // Give
            var message      = "testMessage";
            var communicator = new Communicator("localhost", _port);

            communicator.Connect();
            var communicatorSeenFromServer = await _acceptTask;
            var stream = communicatorSeenFromServer.GetStream();

            // When
            communicator.Send(message);

            byte[] fourBytes = new byte[4];
            stream.Read(fourBytes, 0, 4);
            var messageLen = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(fourBytes, 0));

            byte[] buffer = new byte[messageLen];
            stream.Read(buffer, 0, messageLen);
            var result = System.Text.Encoding.UTF8.GetString(buffer);

            // Then
            Assert.That(String.Equals(message, result));
        }
Пример #18
0
 /// <summary>
 /// Connects to the EV3 using the given serial port.
 /// </summary>
 /// <param name="port">The serial port to use for communicating with
 ///                    the EV3.</param>
 /// <returns>True if connected, false if not connected.</returns>
 public bool Connect(string port)
 {
     return(communicator.Connect(port));
 }