Ejemplo n.º 1
0
        /// <summary>
        /// Connect and test connection
        /// </summary>
        /// <param name="serverIP">The IP address of the server, 
        /// should be the local IP if used as Unity interface</param>
        public MiddleVRPNClient(Remote remote, string addressServer = "127.0.0.1", int port = 8881)
        {
            this.remote = remote;
            try
            {
                //Create a client socket
                client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
                IPEndPoint serverMachine = new IPEndPoint(IPAddress.Parse(addressServer), port);
                client.BeginConnect(serverMachine, new AsyncCallback(ConnectCallback), client);
               /// connectDone.WaitOne();
                DateTime connectionTime = DateTime.Now;
                string peripheral = remote.Name + SEPARATOR + remote.GetHandlerType().ToString();

                //Wait that the client is connected
                //connectDone.WaitOne();  <-- don't work as expected
                while (!client.Connected)
                {
                    Thread.Sleep(1);
                    DateTime currentTime = DateTime.Now;
                    TimeSpan diff = currentTime.Subtract(connectionTime);
                    if (diff.TotalSeconds > 1)
                    {
                        string err = "Client failed to connect to server. Is your IP correct?"
                                        + "Is your UniVRPNity server working?\n";
                        Console.WriteLine(err);
                        throw new TimeoutException(err);
                    }
                }

                Send(client, peripheral);
            }
            catch (Exception e)
            {
                throw new Exception(e.ToString());
            }
        }
Ejemplo n.º 2
0
 public virtual void Start()
 {
     // remote = new RemoteType(name);
     remote = RemoteFactory.CreateRemote(this, Name + "@" + serverAddress.ToString());
 }