Beispiel #1
0
        public async Task <string> WebsocketMessageHelper(MobiledgeXWebSocketClient mxiWS, string url, string message, int timeOutMs)
        {
            await mxiWS.Connect(new Uri(url));

            await Task.Delay(TimeSpan.FromMilliseconds(1000));

            mxiWS.Send(message);
            string output;

            System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();
            stopWatch.Start();
            while (mxiWS.receiveQueue.Count == 0 && stopWatch.ElapsedMilliseconds < timeOutMs)
            {
                //Debug.Log("Waiting for WebSocket Received messgae");
            }
            stopWatch = null;
            mxiWS.receiveQueue.TryDequeue(out output);
            return(output);
        }
Beispiel #2
0
 public void WebSocketTest(string orgName, string appName, string appVers, string proto, int port, int timeOutMs)
 {
     using (MobiledgeXIntegration mxi = new MobiledgeXIntegration(new CarrierInfoClass(), null, new UniqueIDClass(), new TestDeviceInfo()))
     {
         mxi.appName = appName;
         mxi.appVers = appVers;
         mxi.orgName = orgName;
         var getUrlTask = Task.Run(async() =>
         {
             return(await GetUrlHelper(mxi, proto, port));
         });
         string url = getUrlTask.Result + "/ws";
         MobiledgeXWebSocketClient wsClient = new MobiledgeXWebSocketClient();
         var sendWSMessage = Task.Run(async() =>
         {
             return(await WebsocketMessageHelper(wsClient, url, "hello", timeOutMs));
         });
         Assert.True(sendWSMessage.Result == "olleh");
     }
 }