private void OnConnect() { try { txtError.Text = ""; uint dummy = 0; byte[] inOptionValues = new byte[Marshal.SizeOf(dummy) * 3]; BitConverter.GetBytes((uint)1).CopyTo(inOptionValues, 0); BitConverter.GetBytes((uint)5000).CopyTo(inOptionValues, Marshal.SizeOf(dummy)); BitConverter.GetBytes((uint)5000).CopyTo(inOptionValues, Marshal.SizeOf(dummy) * 2); mChannel = TcpServer.CreateClient(txtIPAddress.Text, 9001); mChannel.Socket.IOControl(IOControlCode.KeepAliveValues, inOptionValues, null); mChannel.ChannelError += onerror; mChannel.ChannelDisposed += ondisposed; mChannel.SetPackage <Logic.HeadSizePage>(); mChannel.Package.ReceiveMessage = OnReceive; mChannel.BeginReceive(); Logic.Register register = new Logic.Register(); register.Name = txtUserName.Text; mChannel.Send(register); } catch (Exception e_) { MessageBox.Show(this, e_.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void _Register(IChannel channel, Logic.Register e) { channel.Name = e.Name; Logic.RegisterResponse response = new Logic.RegisterResponse(); channel.Send(response); Logic.OnRegister onreg = new Logic.OnRegister(); onreg.User = new Logic.UserInfo { Name = e.Name, IP = channel.EndPoint.ToString() }; foreach (IChannel item in mServer.GetOnlines()) { if (item != channel) { item.Send(onreg); } } Console.WriteLine("{0} login from {1}", e.Name, channel.EndPoint); }
private void OnConnect() { try { txtError.Text = ""; uint dummy = 0; byte[] inOptionValues = new byte[Marshal.SizeOf(dummy) * 3]; BitConverter.GetBytes((uint)1).CopyTo(inOptionValues, 0); BitConverter.GetBytes((uint)5000).CopyTo(inOptionValues, Marshal.SizeOf(dummy)); BitConverter.GetBytes((uint)5000).CopyTo(inOptionValues, Marshal.SizeOf(dummy) * 2); mChannel = TcpServer.CreateClient(txtIPAddress.Text, 9001); mChannel.Socket.IOControl(IOControlCode.KeepAliveValues, inOptionValues, null); mChannel.ChannelError += onerror; mChannel.ChannelDisposed += ondisposed; mChannel.SetPackage<Logic.HeadSizePage>(); mChannel.Package.ReceiveMessage = OnReceive; mChannel.BeginReceive(); Logic.Register register = new Logic.Register(); register.Name = txtUserName.Text; mChannel.Send(register); } catch (Exception e_) { MessageBox.Show(this, e_.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }