Example #1
0
 /// <summary>
 /// Search a remote device.
 /// </summary>
 /// <param name="vrpnObject">Searched object.</param>
 /// <returns>True if exist, false else.</returns>
 public bool isPresent(IVrpnObject vrpnObject)
 {
     return this[vrpnObject] != null;
 }
Example #2
0
 /// <summary>
 /// Find a remote from it VrpnNet remote object. Iterate on all object : O(n).
 /// </summary>
 /// <param name="name">VrpnNet remote object.</param>
 /// <returns>Found object, null else.</returns>
 public VrpnObjectInfo this[IVrpnObject remote]
 {
     get
     {
         foreach (VrpnObjectInfo r in remotes)
             if (r.Remote == remote)
                 return r;
         return null;
     }
 }
Example #3
0
 /// <summary>
 /// Remove a client when it shutdown the connection.
 /// </summary>
 /// <param name="socket">Client socket.</param>
 /// <param name="sender">Remote object associate to the client.</param>
 void RemoveClient(IVrpnObject sender)
 {
     //sender.GetConnection().Dispose(); // Don't even think about it. Crash at 100%.
     VrpnObjectInfo remote = this.remotes[sender];
     Socket socket = remote.Socket;
     socket.Shutdown(SocketShutdown.Both);
     socket.Close();
     this.remotes.SyncRemove(remote);
     Console.WriteLine("Close client connection.");
 }
Example #4
0
 /// <summary>
 /// Send event to the associate client.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="evt"></param>
 private void SendEvent(IVrpnObject sender, Event evt)
 {
     stream = new MemoryStream();
     formatter.Serialize(stream, evt);
     sendBuffer = stream.GetBuffer();
     Socket conveyor = this.remotes[sender].Socket;
     try
     {
         conveyor.Send(sendBuffer);
     }
     catch (SocketException)
     {
         Console.WriteLine("Client connection error. He maybe quits.");
         this.RemoveClient(sender);
     }
 }
Example #5
0
        /// <summary>
        /// Send event to the associate client.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="evt"></param>
        private void SendEvent(IVrpnObject sender, Event evt)
        {
            stream = new MemoryStream();
            formatter.Serialize(stream, evt);
            sendBuffer = stream.GetBuffer();
            Socket conveyor = this.remotes[sender].Socket;

            try
            {
                // Begin sending the data to the remote device.
                conveyor.BeginSend(sendBuffer, 0, sendBuffer.Length, 0, new AsyncCallback(SendCallback), conveyor);
            }
            catch (SocketException se)
            {
                Console.WriteLine("Sending error " + se.SocketErrorCode + "(" + se.ErrorCode + ") : " + se.Message + " on " + evt.Device);
                //Quit only if socket is disconnected.
                if (!conveyor.Connected)
                {
                    Console.WriteLine("Client connection error. He maybe quits.");
                    this.RemoveClient(sender);
                }
            } catch (Exception e)  {
                Console.WriteLine(e.ToString());
             }
        }