internal void SendData(byte[] send, string v) { byte[] buffer = new byte[send.Length]; Buffer.BlockCopy(send, 0, buffer, 0, send.Length); try { ConnectionSocket.BeginSend(buffer, 0, buffer.Length, SocketFlags.None, delegate { }, null); } catch (SocketException e) { var trace = new StackTrace(e, true); Log.Print(LogType.Error, $"{e.Message}: {e.Source}\n{trace.GetFrame(trace.FrameCount - 1).GetFileName()}:{trace.GetFrame(trace.FrameCount - 1).GetFileLineNumber()}"); Disconnect(); } catch (NullReferenceException e) { var trace = new StackTrace(e, true); Log.Print(LogType.Error, $"{e.Message}: {e.Source}\n{trace.GetFrame(trace.FrameCount - 1).GetFileName()}:{trace.GetFrame(trace.FrameCount - 1).GetFileLineNumber()}"); Disconnect(); } catch (ObjectDisposedException e) { Log.Print(LogType.Error, $"{e.Message}: {e.Source}"); Disconnect(); } }
/// <summary> /// Send data asynchronously to an IP connection /// </summary> /// <param name="name">Name of the connection</param> /// <param name="sendData">Byte array with the data</param> /// <param name="nrbytes">Number of bytes to be sent</param> public bool SendDataAsync(byte[] sendData, int nrbytes) { try { ConnectionSocket.BeginSend(sendData, 0, nrbytes, 0, new AsyncCallback(SendCallback), Address); DataReceived = false; return(true); } catch { ReportError?.Invoke("BeginSend failed in ConnectionBase.SendDataAsync", Address); return(false); } }
public void Send(string data) { try { if (!string.IsNullOrEmpty(data)) { byte[] byteData = Encoding.UTF8.GetBytes(data); ConnectionSocket.BeginSend(byteData, 0, byteData.Length, 0, new AsyncCallback(SendCallback), null); LogTools.Write(this.SessionId, data); } } catch (Exception ex) { LogTools.Write(this.SessionId, ex, "Connection.Send"); } }
/// <summary> /// /// </summary> /// <param name="data"></param> public virtual void Send(byte[] data) { if (ConnectionSocket == null) { return; } if (ConnectionSocket.Connected && data?.LongLength > 0) { try { ConnectionSocket.BeginSend(data, 0, data.Length, SocketFlags.None, new AsyncCallback(SendCallback), ConnectionSocket); } catch { OnDisconnected(); } } }
public void SendData(byte[] send) { var buffer = new byte[send.Length]; Buffer.BlockCopy(send, 0, buffer, 0, send.Length); try { ConnectionSocket.BeginSend(buffer, 0, buffer.Length, SocketFlags.None, delegate { }, null); } catch (SocketException) { Disconnect(); } catch (NullReferenceException) { Disconnect(); } catch (ObjectDisposedException) { Disconnect(); } }