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 _OnLogin(Beetle.IChannel channel, Logic.RegisterResponse e) { Logic.ListUsers list = new Logic.ListUsers(); channel.Send(list); Invoke(new Action <object>(o => { toolStrip2.Enabled = false; groupBox2.Enabled = true; }), new object()); }
private void cmdSend_Click(object sender, EventArgs e) { string tmp = richSay.Rtf; int startindex, endindex; startindex = tmp.IndexOf(@"\viewkind4"); endindex = tmp.LastIndexOf("}"); tmp = tmp.Substring(startindex, endindex - startindex); tmp = tmp.Replace("\\pard", "\\pard\\li220"); string message = string.Format(@"\viewkind4\uc1\pard\sa200\sl276\slmult1\lang2052\f0\cf1\fs22 {0} \cf0 {1} \cf0\line {2}", txtUserName.Text, DateTime.Now, tmp); richSay.Rtf = ""; richSay.Focus(); addSay(message); Logic.Say say = new Logic.Say(); say.Body = tmp; mChannel.Send(say); }
public static int Send(Beetle.IChannel _channel, byte[] vBuf, bool hasCrLf) { if (vBuf.Length < 1) { return(0); } if (_channel.IsDisposed) { return(-1); } bool _ok = false; // 处理 CrLf List <byte> _buf = new List <byte>(vBuf); if (hasCrLf) { _buf.Add(10); _buf.Add(13); } try { Beetle.BytesMessage _bbm = new Beetle.BytesMessage(); _bbm.Value = _buf.ToArray(); _ok = _channel.Send(_bbm); } catch (Exception e_) { MessageBox.Show("-103:" + e_.Message); //Console.WriteLine(e_.Message); return(-103); } return(_ok ? _buf.Count : 0); }
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); } }