/// <summary> /// /// </summary> /// <param name="sipMessage"></param> /// <param name="destination"></param> public void Send(SipMessage sipMessage, DestinationTuple destination) { byte[] message = sipMessage.GetBytes(); CipDataSentEventArgs e = new CipDataSentEventArgs(message, destination); try { this.ConnectionSocket.SendTo(message, SocketFlags.None, (EndPoint)destination.RemoteEndPoint); this.OnDataSent(e); } catch (ObjectDisposedException ex) { throw ex; } catch (SocketException ex) { Console.WriteLine(ex.Message); if (ex.SocketErrorCode == SocketError.WouldBlock) { this.ConnectionSocket.BeginSendTo(message, 0, message.Length, SocketFlags.None, (EndPoint)destination.RemoteEndPoint, new AsyncCallback(this.SentCallback), e); } else { throw ex; } } }
/// <summary> /// /// </summary> /// <param name="e"></param> private void OnDataSent(CipDataSentEventArgs e) { Console.WriteLine(this.server_name + " OnDataSent"); if (this.DataSent != null) { this.DataSent(this, e); } }
/// <summary> /// /// </summary> /// <param name="result"></param> private void SentCallback(IAsyncResult result) { Console.WriteLine(this.server_name + " SentCallback"); try { CipDataSentEventArgs e = (CipDataSentEventArgs)result.AsyncState; this.ConnectionSocket.EndSend(result); this.OnDataSent(e); } catch (Exception ex) { //LogHelper.Error(Assembly.GetExecutingAssembly().GetName().Name, Dns.GetHostName(), (int)ServerType.MS, exception.Message, exception.StackTrace); } }