/// <summary> /// Try sending byte data to the remote host /// </summary> /// <param name="data">The data to send</param> public void Send(byte[] data) { if (this.ConnectionState != ConnectionStatus.Connected) { Connect(); } //throw new InvalidOperationException("Cannot send data, socket is not connected"); SocketError err = new SocketError(); this._client.Client.BeginSend(data, 0, data.Length, SocketFlags.None, out err, new AsyncCallback(cbSendComplete), this._client.Client); if (err != SocketError.Success) { Console.WriteLine("Send Error" + err.ToString()); Action doDCHost = new Action(DisconnectByHost); doDCHost.Invoke(); } else { if (DataSended != null && data != null) { DataSended.BeginInvoke(this, data, null, this); } } }
//public void Send(ApiCommand command) //{ // Send((byte)command, new byte[0]); //} //public void Send(byte command) //{ // Send(command, new byte[0]); //} //public void Send(byte command, object obj) //{ // Send(command, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(obj))); //} //public void Send(ApiCommand command, object obj) //{ // Send((byte)command, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(obj))); //} //public void Send(ApiCommand command, byte[] data) //{ // Send((byte)command, data); //} public void Send(CommandBody content) { Send(Serialize(content)); DataSended?.Invoke(this, new DataReceivedEventArgs(content)); }
public void UpLoad() { InterProcSocket.Singleton.Value.PostData(_dataset[new Random().Next(0, 10000)].Substring(1)); DataSended?.Invoke(); }
private void OnDataSended(DataSendedEventArgs e) { DataSended?.Invoke(this, e); }