public void Connect(string nick, string port) { this.d++; SetText($"Connecting...\r\n"); this.nickn = nick; this.cport = port; TcpChannel c = new TcpChannel(Int32.Parse(port)); ChannelServices.RegisterChannel(c, false); CChat cc = new CChat(nick); RemotingServices.Marshal(cc, "ClientChat" + this.d, typeof(CChat)); this.s = (IServer)Activator.GetObject(typeof(IServer), "tcp://[IP]:[PORT]/SuperChat"); this.turl = "tcp://" + GetLocalIPAddress() + ":" + port + "/ClientChat" + this.d; if (s.AddUser(nick, turl) == false) //Check for already taken nickname { SetText($"Nickname already taken. Try again.\r\n"); c.StopListening(null); RemotingServices.Disconnect(this); ChannelServices.UnregisterChannel(c); c = null; } else { SetText($"Connected!\r\n"); portButton.Enabled = false; } }