예제 #1
0
        List <Client_Wrapper> AddViewer(Client_Wrapper wrapper)
        {
            lock (ClientsLock)
            {//ensure the Remove Function doesnt interleave here!!
                var possibleserver = _Clients[wrapper.ClientObject.Dst_ID];
                if (possibleserver != null)
                {
                    if (possibleserver.ClientObject.Host == Client.Host_Type.Server)
                    {                                                     //viewers can only connect to servers... Duh!
                        if (possibleserver.ClientObject.Status != Client.Connection_Status.Pending)
                        {                                                 //the server has to be in a pending state in order to connect to it
                            Debug.WriteLine("Viewer attempting to connect to server which is not in a pending state. . . setting viewer to disconnect");
                            wrapper.SocketObject.ShouldDisconnect = true; //set to disconnect
                            return(null);
                        }

                        wrapper.ClientObject.Src_ID = GetID();
                        if (wrapper.ClientObject.Src_ID < 0)
                        {                                                 //if there are no ids left.. get out
                            Debug.WriteLine("There are no more Ids, setting to disconnect");
                            wrapper.SocketObject.ShouldDisconnect = true; //set to disconnect
                            return(null);
                        }
                        Debug.WriteLine("Wiring up viewer and server .. Good Connect  . . ");
                        //good  Connect.. add the viewer and pair them up
                        wrapper.ClientObject.Status           = possibleserver.ClientObject.Status = Client.Connection_Status.Paired;
                        possibleserver.ClientObject.Dst_ID    = wrapper.ClientObject.Src_ID;//match up the ids
                        _Clients[wrapper.ClientObject.Src_ID] = wrapper;
                        return(new List <Client_Wrapper> {
                            possibleserver, wrapper
                        });
                    }
                    else
                    {
                        Debug.WriteLine("Viewer attempting to connect to a non server.. this doesnt make sense.. setting viewer to disconnect");
                        wrapper.SocketObject.ShouldDisconnect = true;//set to disconnect
                        return(null);
                    }
                }
                else
                {//no server to connect to just yet.. allow the connection through, and assign a pending state, there is a timeout for non paired connections which will fire off if no pairing is made
                    wrapper.ClientObject.Src_ID = GetID();
                    if (wrapper.ClientObject.Src_ID < 0)
                    {                                                 //if there are no ids left.. get out
                        Debug.WriteLine("There are no more Ids, setting to disconnect");
                        wrapper.SocketObject.ShouldDisconnect = true; //set to disconnect
                        return(null);
                    }
                    Debug.WriteLine("Viewer connected, but there is no valid server to pair with.");
                    wrapper.ClientObject.Status           = Client.Connection_Status.Pending;
                    _Clients[wrapper.ClientObject.Src_ID] = wrapper;
                    return(new List <Client_Wrapper> {
                        wrapper
                    });
                }
            }
        }
예제 #2
0
 static void Send(Client_Wrapper c)//this is synchronous .. SUE ME!
 {
     if (c.SocketObject.BufferCount > 0 && c.SocketObject.OtherSocketObject != null)
     {
         var otherside = c.SocketObject.OtherSocketObject;
         otherside.LastTimeHeard = DateTime.Now;
         int offset = 0;
         while (offset < c.SocketObject.BufferCount)
         {
             offset += otherside.SocketObject.Send(c.SocketObject.buffer, offset, c.SocketObject.BufferCount - offset, SocketFlags.None);
         }
         c.SocketObject.BufferCount = 0;
     }
 }
예제 #3
0
 static int Get_DisconnectTime(Client_Wrapper o)
 {
     if (o == null)
     {
         return(Constants.VIEWER_DISCONNECT_TIMEOUT);
     }
     if (o.ClientObject == null)
     {
         return(Constants.VIEWER_DISCONNECT_TIMEOUT);
     }
     if (o.ClientObject.Host == RemoteDesktop_CSLibrary.Client.Host_Type.Server)
     {
         return(Constants.SERVER_DISCONNECT_TIMEOUT);
     }
     else
     {
         return(Constants.VIEWER_DISCONNECT_TIMEOUT);
     }
 }
예제 #4
0
        void Disconnect(Client_Wrapper state)
        {
            try
            {
                //a lock is needed because a server or viewer can possibly disconnect at a very close time so I cannot have both calling at the same time
                lock (DisconectLock)
                {
                    if (state.SocketObject.Disconnected)
                    {
                        return;//already done
                    }
                    state.SocketObject.Disconnected = true;
                    //       LOG += "Disconnecting " + state.ClientObject.Firewall_IP + ":" + state.ClientObject.Firewall_Port.ToString() + "<br/>";

                    Debug.WriteLine("Disconnecting " + state.ClientObject.Firewall_IP + ":" + state.ClientObject.Firewall_Port.ToString());
                    Debug.Assert(Connected[state.ClientObject.Src_ID] != null);
                    Connected[state.ClientObject.Src_ID].SocketObject.SocketObject.Close();
                    Connected[state.ClientObject.Src_ID].SocketObject.SocketObject.Dispose();
                    Connected[state.ClientObject.Src_ID] = null;

                    var otherid = state.ClientObject.Dst_ID;
                    if (otherid >= 0)
                    {
                        //        LOG += "Disconnecting " + Connected[otherid].ClientObject.Firewall_IP + ":" + Connected[otherid].ClientObject.Firewall_Port.ToString() + "<br/>";
                        Debug.WriteLine("Disconnecting " + Connected[otherid].ClientObject.Firewall_IP + ":" + Connected[otherid].ClientObject.Firewall_Port.ToString());
                        Connected[otherid].SocketObject.SocketObject.Close();
                        Connected[otherid].SocketObject.SocketObject.Dispose();
                        Connected[otherid].SocketObject.Disconnected = true;
                        Connected[otherid] = null;
                    }
                }
                //now that the cleanup is done in this area, tell the manager, which will free up the hew IDS
                ClientManager.Remove(state.ClientObject);
            }
            catch (Exception e)
            {
                //   LOG += "Error In Disconnect <br/>";
                Debug.WriteLine("Error In Disconnect");
                Debug.WriteLine(e.Message);
                //   LOG += e.Message + "<br/>";
            }
        }
예제 #5
0
 List <Client_Wrapper> AddServer(Client_Wrapper wrapper)
 {
     lock (ClientsLock)
     {//ensure the Remove Function doesnt interleave here!!
         var serverobject = _Clients[wrapper.ClientObject.Src_ID];
         if (serverobject == null)
         {
             Debug.WriteLine("Server attempting to connect with a bad ID, setting to disconnect.");
             wrapper.SocketObject.ShouldDisconnect = true;
             return(null);
         }
         if (serverobject.ClientObject.Host != Client.Host_Type.Server)
         {
             Debug.WriteLine("Server attempting to connect with a bad ID, setting to disconnect. Host != Server");
             wrapper.SocketObject.ShouldDisconnect = true;
             return(null);
         }
         if (serverobject.ClientObject.Status == Client.Connection_Status.Reserved)
         {
             serverobject.ClientObject.Status = Client.Connection_Status.Pending;
         }
         serverobject.ClientObject.ConnectTime = DateTime.Now;
         serverobject.SocketObject             = wrapper.SocketObject;// make sure to set this
         //search for a viewer, that is trying to connect to this server, and in a pending state
         var posviewer = _Clients.FirstOrDefault(a => a != null && a.ClientObject.Host == Client.Host_Type.Viewer && a.ClientObject.Dst_ID == wrapper.ClientObject.Src_ID && a.ClientObject.Status == Client.Connection_Status.Pending);
         if (posviewer != null)
         {//found a viewer!!! pair up!
             Debug.WriteLine("Viewer found to pair with server.. Wiring up!");
             serverobject.ClientObject.Status = posviewer.ClientObject.Status = Client.Connection_Status.Paired;
             serverobject.ClientObject.Dst_ID = posviewer.ClientObject.Src_ID;
             return(new List <Client_Wrapper> {
                 serverobject, posviewer
             });
         }
         //no viewer found.. just wait . . .
         return(new List <Client_Wrapper> {
             serverobject
         });
     }
 }
예제 #6
0
        //this is called by a server to get an ID slot
        public Client ReserveID(string ip, string computername, string username, string mac, string sessionId)
        {
            var id = -1;
            //check for a previous connection
            var prev = _Clients.FirstOrDefault(a => a != null && a.ClientObject.Mac_Address == mac && a.ClientObject.SessionID == sessionId && a.ClientObject.Host == Client.Host_Type.Server && a.ClientObject.Status == Client.Connection_Status.Reserved);//check for a reconnecting client

            if (prev != null)
            {//update any info, computer name can change, usersname, etc...
                prev.ClientObject.UserName     = username;
                prev.ClientObject.ComputerName = computername;
                prev.ClientObject.ConnectTime  = DateTime.Now;
                prev.ClientObject.Status       = Client.Connection_Status.Reserved;
            }
            else if (Ids.TryDequeue(out id))
            {//new client, get a new id and fill
                prev = new Client_Wrapper();
                prev.ClientObject.ComputerName = computername;
                prev.ClientObject.UserName     = username;
                prev.ClientObject.Mac_Address  = mac;
                prev.ClientObject.SessionID    = sessionId;
                prev.ClientObject.Host         = Client.Host_Type.Server;
                prev.ClientObject.ConnectTime  = DateTime.Now;
                prev.ClientObject.Src_ID       = id;
                prev.ClientObject.Dst_ID       = -1;
                prev.ClientObject.Firewall_IP  = ip;
                prev.ClientObject.Status       = Client.Connection_Status.Reserved;
                using (var aes = new AesManaged())
                {
                    aes.KeySize = 256;
                    aes.GenerateKey();
                    prev.ClientObject.AES_Session_Key = ByteArrayToString(aes.Key);
                }
                _Clients[id] = prev;
            }
            return(prev.ClientObject);
        }
예제 #7
0
 void BeginReceive(Client_Wrapper state)
 {
     state.SocketObject.SocketObject.BeginReceive(state.SocketObject.buffer, state.SocketObject.BufferCount, state.SocketObject.buffer.Length - state.SocketObject.BufferCount, 0, new AsyncCallback(ReadCallback), state);
 }
예제 #8
0
        public List <Client_Wrapper> Add(ServerSocket c, int dst_id, int src_id)
        {
            //BEGING VALIDATION
            Debug.WriteLine("Attempting to pair connections dst_id " + dst_id.ToString() + "src_id " + src_id);

            var newclient = new Client_Wrapper();

            newclient.SocketObject             = c;
            newclient.ClientObject.ConnectTime = DateTime.Now;


            if (dst_id == -1)
            {
                newclient.ClientObject.Host = Client.Host_Type.Server;
            }
            else if (src_id == -1)
            {
                newclient.ClientObject.Host = Client.Host_Type.Viewer;
                //servers have their info set when they get an ID, viewers dont until they are added
                var remoteIpEndPoint = newclient.SocketObject.SocketObject.RemoteEndPoint as System.Net.IPEndPoint;
                newclient.ClientObject.Firewall_IP   = remoteIpEndPoint.Address.ToString();
                newclient.ClientObject.Firewall_Port = remoteIpEndPoint.Port.ToString();
            }
            else
            {
                c.ShouldDisconnect = true;
                Debug.WriteLine("Disconnecting connection because of unknown client type");
                return(null);
            }
            //attempt to pair up!
            //check id range
            if (newclient.ClientObject.Host == Client.Host_Type.Viewer && (dst_id < 0 || dst_id >= Constants.MAXCLIENTS))
            {
                c.ShouldDisconnect = true;
                Debug.WriteLine("Disconnecting connection because a viewer cannot connect to a value less than 0 Or greater than " + Constants.MAXCLIENTS.ToString());
                return(null);
            }
            if (newclient.ClientObject.Host == Client.Host_Type.Server && (src_id < 0 || dst_id >= Constants.MAXCLIENTS))
            {
                c.ShouldDisconnect = true;
                Debug.WriteLine("Disconnecting connection because a server cannot have a src_id to a value less than 0Or greater than " + Constants.MAXCLIENTS.ToString());
                return(null);
            }
            //ids are going to be corrected below
            newclient.ClientObject.Dst_ID = dst_id;
            newclient.ClientObject.Src_ID = src_id;
            List <Client_Wrapper> ret = null;

            //check if ids are already in use
            //by now the range of the IDs is good and the code and goto the next step
            if (newclient.ClientObject.Host == Client.Host_Type.Viewer)
            {
                ret = AddViewer(newclient);
            }
            else if (newclient.ClientObject.Host == Client.Host_Type.Server)
            {
                ret = AddServer(newclient);
            }
            else
            {
                Debug.Assert(false);
            }
            if (ret != null)
            {//either a pairing occured or a client connected
                if (ret.Count == 1)
                {
                    if (OnClientConnectEvent != null)
                    {
                        OnClientConnectEvent(ret.Select(a => a.ClientObject).ToList());
                    }
                }
                else if (ret.Count == 2)
                {
                    if (OnPairedEvent != null)
                    {
                        OnClientConnectEvent(ret.Select(a => a.ClientObject).ToList());
                    }
                }
                else
                {
                    Debug.Assert(false);//never hit this!!
                }
            }
            return(ret);
        }
예제 #9
0
        void Disconnect(Client_Wrapper state)
        {
            try
            {
                //a lock is needed because a server or viewer can possibly disconnect at a very close time so I cannot have both calling at the same time
                lock (DisconectLock)
                {
                    if (state.SocketObject.Disconnected)
                        return;//already done
                    state.SocketObject.Disconnected = true;
             //       LOG += "Disconnecting " + state.ClientObject.Firewall_IP + ":" + state.ClientObject.Firewall_Port.ToString() + "<br/>";

                    Debug.WriteLine("Disconnecting " + state.ClientObject.Firewall_IP + ":" + state.ClientObject.Firewall_Port.ToString());
                    Debug.Assert(Connected[state.ClientObject.Src_ID] != null);
                    Connected[state.ClientObject.Src_ID].SocketObject.SocketObject.Close();
                    Connected[state.ClientObject.Src_ID].SocketObject.SocketObject.Dispose();
                    Connected[state.ClientObject.Src_ID] = null;

                    var otherid = state.ClientObject.Dst_ID;
                    if (otherid >= 0)
                    {
                //        LOG += "Disconnecting " + Connected[otherid].ClientObject.Firewall_IP + ":" + Connected[otherid].ClientObject.Firewall_Port.ToString() + "<br/>";
                        Debug.WriteLine("Disconnecting " + Connected[otherid].ClientObject.Firewall_IP + ":" + Connected[otherid].ClientObject.Firewall_Port.ToString());
                        Connected[otherid].SocketObject.SocketObject.Close();
                        Connected[otherid].SocketObject.SocketObject.Dispose();
                        Connected[otherid].SocketObject.Disconnected = true;
                        Connected[otherid] = null;
                    }
                }
                //now that the cleanup is done in this area, tell the manager, which will free up the hew IDS 
                ClientManager.Remove(state.ClientObject);

            }
            catch (Exception e)
            {
             //   LOG += "Error In Disconnect <br/>";
                Debug.WriteLine("Error In Disconnect");
                Debug.WriteLine(e.Message);
             //   LOG += e.Message + "<br/>";

            }
        }
예제 #10
0
 void BeginReceive(Client_Wrapper state)
 {
     state.SocketObject.SocketObject.BeginReceive(state.SocketObject.buffer, state.SocketObject.BufferCount, state.SocketObject.buffer.Length - state.SocketObject.BufferCount, 0, new AsyncCallback(ReadCallback), state);
 }
예제 #11
0
 static void Send(Client_Wrapper c)//this is synchronous .. SUE ME!
 {
     if (c.SocketObject.BufferCount > 0 && c.SocketObject.OtherSocketObject != null)
     {
         var otherside = c.SocketObject.OtherSocketObject;
         otherside.LastTimeHeard = DateTime.Now;
         int offset = 0;
         while (offset < c.SocketObject.BufferCount)
         {
             offset += otherside.SocketObject.Send(c.SocketObject.buffer, offset, c.SocketObject.BufferCount - offset, SocketFlags.None);
         }
         c.SocketObject.BufferCount = 0;
     }
 }
예제 #12
0
 static int Get_DisconnectTime(Client_Wrapper o)
 {
     if (o == null)
         return Constants.VIEWER_DISCONNECT_TIMEOUT;
     if (o.ClientObject == null)
         return Constants.VIEWER_DISCONNECT_TIMEOUT;
     if (o.ClientObject.Host == RemoteDesktop_CSLibrary.Client.Host_Type.Server)
         return Constants.SERVER_DISCONNECT_TIMEOUT;
     else
         return Constants.VIEWER_DISCONNECT_TIMEOUT;
 }
예제 #13
0
        public List<Client_Wrapper> Add(ServerSocket c, int dst_id, int src_id)
        {
            //BEGING VALIDATION 
            Debug.WriteLine("Attempting to pair connections dst_id " + dst_id.ToString() + "src_id " + src_id);

            var newclient = new Client_Wrapper();
            newclient.SocketObject = c;
            newclient.ClientObject.ConnectTime = DateTime.Now;


            if(dst_id == -1)
                newclient.ClientObject.Host = Client.Host_Type.Server;
            else if(src_id == -1)
            {
                newclient.ClientObject.Host = Client.Host_Type.Viewer;
                //servers have their info set when they get an ID, viewers dont until they are added
                var remoteIpEndPoint = newclient.SocketObject.SocketObject.RemoteEndPoint as System.Net.IPEndPoint;
                newclient.ClientObject.Firewall_IP = remoteIpEndPoint.Address.ToString();
                newclient.ClientObject.Firewall_Port = remoteIpEndPoint.Port.ToString();

            } else
            {
                c.ShouldDisconnect = true;
                Debug.WriteLine("Disconnecting connection because of unknown client type");
                return null;
            }
            //attempt to pair up!
            //check id range
            if(newclient.ClientObject.Host == Client.Host_Type.Viewer && (dst_id < 0 || dst_id >= Constants.MAXCLIENTS))
            {
                c.ShouldDisconnect = true;
                Debug.WriteLine("Disconnecting connection because a viewer cannot connect to a value less than 0 Or greater than " + Constants.MAXCLIENTS.ToString());
                return null;
            }
            if(newclient.ClientObject.Host == Client.Host_Type.Server && (src_id < 0 || dst_id >= Constants.MAXCLIENTS))
            {
                c.ShouldDisconnect = true;
                Debug.WriteLine("Disconnecting connection because a server cannot have a src_id to a value less than 0Or greater than " + Constants.MAXCLIENTS.ToString());
                return null;
            }
            //ids are going to be corrected below
            newclient.ClientObject.Dst_ID = dst_id;
            newclient.ClientObject.Src_ID = src_id;
            List<Client_Wrapper> ret = null;
            //check if ids are already in use
            //by now the range of the IDs is good and the code and goto the next step
            if(newclient.ClientObject.Host == Client.Host_Type.Viewer)
            {
                ret = AddViewer(newclient);
            } else if(newclient.ClientObject.Host == Client.Host_Type.Server)
            {
                ret = AddServer(newclient);
            } else
            {
                Debug.Assert(false);
            }
            if(ret != null)
            {//either a pairing occured or a client connected
                if(ret.Count == 1)
                {
                    if(OnClientConnectEvent != null)
                        OnClientConnectEvent(ret.Select(a => a.ClientObject).ToList());
                } else if(ret.Count == 2)
                {
                    if(OnPairedEvent != null)
                        OnClientConnectEvent(ret.Select(a => a.ClientObject).ToList());
                } else
                    Debug.Assert(false);//never hit this!!
            }
            return ret;
        }
예제 #14
0
        //this is called by a server to get an ID slot
        public Client ReserveID(string ip, string computername, string username, string mac, string sessionId)
        {

            var id = -1;
            //check for a previous connection
            var prev = _Clients.FirstOrDefault(a => a != null && a.ClientObject.Mac_Address == mac && a.ClientObject.SessionID == sessionId && a.ClientObject.Host == Client.Host_Type.Server && a.ClientObject.Status == Client.Connection_Status.Reserved);//check for a reconnecting client
            if(prev != null)
            {//update any info, computer name can change, usersname, etc...
                prev.ClientObject.UserName = username;
                prev.ClientObject.ComputerName = computername;
                prev.ClientObject.ConnectTime = DateTime.Now;
                prev.ClientObject.Status = Client.Connection_Status.Reserved;

            } else if(Ids.TryDequeue(out id))
            {//new client, get a new id and fill
                prev = new Client_Wrapper();
                prev.ClientObject.ComputerName = computername;
                prev.ClientObject.UserName = username;
                prev.ClientObject.Mac_Address = mac;
                prev.ClientObject.SessionID = sessionId;
                prev.ClientObject.Host = Client.Host_Type.Server;
                prev.ClientObject.ConnectTime = DateTime.Now;
                prev.ClientObject.Src_ID = id;
                prev.ClientObject.Dst_ID = -1;
                prev.ClientObject.Firewall_IP = ip;
                prev.ClientObject.Status = Client.Connection_Status.Reserved;
                using(var aes = new AesManaged())
                {
                    aes.KeySize = 256;
                    aes.GenerateKey();
                    prev.ClientObject.AES_Session_Key = ByteArrayToString(aes.Key);
                }
                _Clients[id] = prev;

            }
            return prev.ClientObject;
        }
예제 #15
0
        List<Client_Wrapper> AddServer(Client_Wrapper wrapper)
        {
            lock(ClientsLock)
            {//ensure the Remove Function doesnt interleave here!!
                var serverobject = _Clients[wrapper.ClientObject.Src_ID];
                if(serverobject == null)
                {
                    Debug.WriteLine("Server attempting to connect with a bad ID, setting to disconnect.");
                    wrapper.SocketObject.ShouldDisconnect = true;
                    return null;
                }
                if(serverobject.ClientObject.Host != Client.Host_Type.Server)
                {
                    Debug.WriteLine("Server attempting to connect with a bad ID, setting to disconnect. Host != Server");
                    wrapper.SocketObject.ShouldDisconnect = true;
                    return null;
                }
                if(serverobject.ClientObject.Status == Client.Connection_Status.Reserved)
                {
                    serverobject.ClientObject.Status = Client.Connection_Status.Pending;
                }
                serverobject.ClientObject.ConnectTime = DateTime.Now;
                serverobject.SocketObject = wrapper.SocketObject;// make sure to set this
                //search for a viewer, that is trying to connect to this server, and in a pending state
                var posviewer = _Clients.FirstOrDefault(a => a != null && a.ClientObject.Host == Client.Host_Type.Viewer && a.ClientObject.Dst_ID == wrapper.ClientObject.Src_ID && a.ClientObject.Status == Client.Connection_Status.Pending);
                if(posviewer != null)
                {//found a viewer!!! pair up!
                    Debug.WriteLine("Viewer found to pair with server.. Wiring up!");
                    serverobject.ClientObject.Status = posviewer.ClientObject.Status = Client.Connection_Status.Paired;
                    serverobject.ClientObject.Dst_ID = posviewer.ClientObject.Src_ID;
                    return new List<Client_Wrapper> { serverobject, posviewer };
                }
                //no viewer found.. just wait . . . 
                return new List<Client_Wrapper> { serverobject };
            }

        }
예제 #16
0
        List<Client_Wrapper> AddViewer(Client_Wrapper wrapper)
        {

            lock(ClientsLock)
            {//ensure the Remove Function doesnt interleave here!!
                var possibleserver = _Clients[wrapper.ClientObject.Dst_ID];
                if(possibleserver != null)
                {
                    if(possibleserver.ClientObject.Host == Client.Host_Type.Server)
                    {//viewers can only connect to servers... Duh!
                        if(possibleserver.ClientObject.Status != Client.Connection_Status.Pending)
                        {//the server has to be in a pending state in order to connect to it
                            Debug.WriteLine("Viewer attempting to connect to server which is not in a pending state. . . setting viewer to disconnect");
                            wrapper.SocketObject.ShouldDisconnect = true;//set to disconnect
                            return null;
                        }

                        wrapper.ClientObject.Src_ID = GetID();
                        if(wrapper.ClientObject.Src_ID < 0)
                        {//if there are no ids left.. get out
                            Debug.WriteLine("There are no more Ids, setting to disconnect");
                            wrapper.SocketObject.ShouldDisconnect = true;//set to disconnect
                            return null;
                        }
                        Debug.WriteLine("Wiring up viewer and server .. Good Connect  . . ");
                        //good  Connect.. add the viewer and pair them up
                        wrapper.ClientObject.Status = possibleserver.ClientObject.Status = Client.Connection_Status.Paired;
                        possibleserver.ClientObject.Dst_ID = wrapper.ClientObject.Src_ID;//match up the ids
                        _Clients[wrapper.ClientObject.Src_ID] = wrapper;
                        return new List<Client_Wrapper> { possibleserver, wrapper };
                    } else
                    {
                        Debug.WriteLine("Viewer attempting to connect to a non server.. this doesnt make sense.. setting viewer to disconnect");
                        wrapper.SocketObject.ShouldDisconnect = true;//set to disconnect
                        return null;
                    }
                } else
                {//no server to connect to just yet.. allow the connection through, and assign a pending state, there is a timeout for non paired connections which will fire off if no pairing is made
                    wrapper.ClientObject.Src_ID = GetID();
                    if(wrapper.ClientObject.Src_ID < 0)
                    {//if there are no ids left.. get out
                        Debug.WriteLine("There are no more Ids, setting to disconnect");
                        wrapper.SocketObject.ShouldDisconnect = true;//set to disconnect
                        return null;
                    }
                    Debug.WriteLine("Viewer connected, but there is no valid server to pair with.");
                    wrapper.ClientObject.Status = Client.Connection_Status.Pending;
                    _Clients[wrapper.ClientObject.Src_ID] = wrapper;
                    return new List<Client_Wrapper> { wrapper };
                }
            }

        }