本文整理汇总了C#中SIPSorcery.SIP.SIPEndPoint.GetIPEndPoint方法的典型用法代码示例。如果您正苦于以下问题:C# SIPEndPoint.GetIPEndPoint方法的具体用法?C# SIPEndPoint.GetIPEndPoint怎么用?C# SIPEndPoint.GetIPEndPoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SIPSorcery.SIP.SIPEndPoint
的用法示例。
在下文中一共展示了SIPEndPoint.GetIPEndPoint方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendRaw
/// <summary>
/// Allows raw bytes to be sent from one of the SIPTransport sockets. This should not be used for SIP payloads and instead is
/// provided to allow other types of payloads to be multi-plexed on the SIP socket. Examples are sending NAT keep alives and
/// STUN responses where it's useful to use the same socket as the SIP packets.
/// </summary>
public void SendRaw(SIPEndPoint localSIPEndPoint, SIPEndPoint destinationEndPoint, byte[] buffer)
{
if (destinationEndPoint != null && destinationEndPoint.Address.Equals(BlackholeAddress))
{
// Ignore packet, it's destined for the blackhole.
return;
}
if (m_sipChannels.Count == 0)
{
throw new ApplicationException("No channels are configured in the SIP transport layer. The data could not be sent.");
}
SIPChannel sendSIPChannel = FindSIPChannel(localSIPEndPoint);
if (sendSIPChannel != null)
{
sendSIPChannel.Send(destinationEndPoint.GetIPEndPoint(), buffer);
}
else
{
logger.Warn("No SIPChannel could be found for " + localSIPEndPoint + " in SIPTransport.SendRaw, sending to " + destinationEndPoint.ToString() + ".");
//logger.Warn(Encoding.UTF8.GetString(buffer));
}
}
示例2: SIPMessageReceived
private void SIPMessageReceived(SIPChannel sipChannel, SIPEndPoint remoteEndPoint, byte[] buffer)
{
string rawSIPMessage = null;
try
{
if (buffer != null && buffer.Length > 0)
{
if ((buffer[0] == 0x0 || buffer[0] == 0x1) && buffer.Length >= 20)
{
// Treat any messages that cannot be SIP as STUN requests.
if (STUNRequestReceived != null)
{
STUNRequestReceived(sipChannel.SIPChannelEndPoint.GetIPEndPoint(), remoteEndPoint.GetIPEndPoint(), buffer, buffer.Length);
#if !SILVERLIGHT
if (PerformanceMonitorPrefix != null)
{
SIPSorceryPerformanceMonitor.IncrementCounter(PerformanceMonitorPrefix + SIPSorceryPerformanceMonitor.SIP_TRANSPORT_STUN_REQUESTS_PER_SECOND_SUFFIX);
}
#endif
}
}
else
{
// Treat all messages that don't match STUN requests as SIP.
if (buffer.Length > SIPConstants.SIP_MAXIMUM_RECEIVE_LENGTH)
{
string rawErrorMessage = Encoding.UTF8.GetString(buffer, 0, 1024) + "\r\n..truncated";
FireSIPBadRequestInTraceEvent(sipChannel.SIPChannelEndPoint, remoteEndPoint, "SIP message too large, " + buffer.Length + " bytes, maximum allowed is " + SIPConstants.SIP_MAXIMUM_RECEIVE_LENGTH + " bytes.", SIPValidationFieldsEnum.Request, rawErrorMessage);
SIPResponse tooLargeResponse = GetResponse(sipChannel.SIPChannelEndPoint, remoteEndPoint, SIPResponseStatusCodesEnum.MessageTooLarge, null);
SendResponse(tooLargeResponse);
#if !SILVERLIGHT
if (PerformanceMonitorPrefix != null)
{
SIPSorceryPerformanceMonitor.IncrementCounter(PerformanceMonitorPrefix + SIPSorceryPerformanceMonitor.SIP_TRANSPORT_SIP_BAD_MESSAGES_PER_SECOND_SUFFIX);
}
#endif
}
else
{
rawSIPMessage = Encoding.UTF8.GetString(buffer, 0, buffer.Length);
if (rawSIPMessage.IsNullOrBlank())
{
// An emptry transmission has been received. More than likely this is a NAT keep alive and can be disregarded.
//FireSIPBadRequestInTraceEvent(sipChannel.SIPChannelEndPoint, remoteEndPoint, "No printable characters, length " + buffer.Length + " bytes.", SIPValidationFieldsEnum.Unknown, null);
#if !SILVERLIGHT
if (PerformanceMonitorPrefix != null)
{
// SIPSorceryPerformanceMonitor.IncrementCounter(PerformanceMonitorPrefix + SIPSorceryPerformanceMonitor.SIP_TRANSPORT_SIP_BAD_MESSAGES_PER_SECOND_SUFFIX);
}
#endif
return;
}
else if (!rawSIPMessage.Contains("SIP"))
{
FireSIPBadRequestInTraceEvent(sipChannel.SIPChannelEndPoint, remoteEndPoint, "Missing SIP string.", SIPValidationFieldsEnum.NoSIPString, rawSIPMessage);
#if !SILVERLIGHT
if (PerformanceMonitorPrefix != null)
{
SIPSorceryPerformanceMonitor.IncrementCounter(PerformanceMonitorPrefix + SIPSorceryPerformanceMonitor.SIP_TRANSPORT_SIP_BAD_MESSAGES_PER_SECOND_SUFFIX);
}
#endif
return;
}
SIPMessage sipMessage = SIPMessage.ParseSIPMessage(rawSIPMessage, sipChannel.SIPChannelEndPoint, remoteEndPoint);
if (sipMessage != null)
{
if (sipMessage.SIPMessageType == SIPMessageTypesEnum.Response)
{
#region SIP Response.
try
{
#if !SILVERLIGHT
if (PerformanceMonitorPrefix != null)
{
SIPSorceryPerformanceMonitor.IncrementCounter(PerformanceMonitorPrefix + SIPSorceryPerformanceMonitor.SIP_TRANSPORT_SIP_RESPONSES_PER_SECOND_SUFFIX);
}
#endif
SIPResponse sipResponse = SIPResponse.ParseSIPResponse(sipMessage);
if (SIPResponseInTraceEvent != null)
{
FireSIPResponseInTraceEvent(sipChannel.SIPChannelEndPoint, remoteEndPoint, sipResponse);
}
if (m_transactionEngine != null && m_transactionEngine.Exists(sipResponse))
{
SIPTransaction transaction = m_transactionEngine.GetTransaction(sipResponse);
if (transaction.TransactionState != SIPTransactionStatesEnum.Completed)
//.........这里部分代码省略.........
示例3: GetResponse
/// <summary>
/// Used to create a SIP response when it was not possible to parse the incoming SIP request.
/// </summary>
public SIPResponse GetResponse(SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPResponseStatusCodesEnum responseCode, string reasonPhrase)
{
try
{
if (localSIPEndPoint == null)
{
localSIPEndPoint = GetDefaultSIPEndPoint();
}
SIPResponse response = new SIPResponse(responseCode, reasonPhrase, localSIPEndPoint);
SIPSchemesEnum sipScheme = (localSIPEndPoint.Protocol == SIPProtocolsEnum.tls) ? SIPSchemesEnum.sips : SIPSchemesEnum.sip;
SIPFromHeader from = new SIPFromHeader(null, new SIPURI(sipScheme, localSIPEndPoint), null);
SIPToHeader to = new SIPToHeader(null, new SIPURI(sipScheme, localSIPEndPoint), null);
int cSeq = 1;
string callId = CallProperties.CreateNewCallId();
response.Header = new SIPHeader(from, to, cSeq, callId);
response.Header.CSeqMethod = SIPMethodsEnum.NONE;
response.Header.Vias.PushViaHeader(new SIPViaHeader(new SIPEndPoint(localSIPEndPoint.Protocol, remoteEndPoint.GetIPEndPoint()), CallProperties.CreateBranchId()));
response.Header.MaxForwards = Int32.MinValue;
response.Header.Allow = ALLOWED_SIP_METHODS;
return response;
}
catch (Exception excp)
{
logger.Error("Exception SIPTransport GetResponse. " + excp.Message);
throw;
}
}
示例4: SendResponse
private void SendResponse(SIPChannel sipChannel, SIPEndPoint dstEndPoint, SIPResponse sipResponse)
{
try
{
if (dstEndPoint != null && dstEndPoint.Address.Equals(BlackholeAddress))
{
// Ignore packet, it's destined for the blackhole.
return;
}
if (m_sipChannels.Count == 0)
{
throw new ApplicationException("No channels are configured in the SIP transport layer. The response could not be sent.");
}
sipResponse.Header.ContentLength = (sipResponse.Body.NotNullOrBlank()) ? Encoding.UTF8.GetByteCount(sipResponse.Body) : 0;
sipChannel.Send(dstEndPoint.GetIPEndPoint(), Encoding.UTF8.GetBytes(sipResponse.ToString()));
if (SIPRequestOutTraceEvent != null)
{
FireSIPResponseOutTraceEvent(sipChannel.SIPChannelEndPoint, dstEndPoint, sipResponse);
}
}
catch (ApplicationException appExcp)
{
logger.Warn("ApplicationException SIPTransport SendResponse. " + appExcp.Message);
}
}
示例5: SendRequest
private void SendRequest(SIPChannel sipChannel, SIPEndPoint dstEndPoint, SIPRequest sipRequest)
{
try
{
if (dstEndPoint != null && dstEndPoint.Address.Equals(BlackholeAddress))
{
// Ignore packet, it's destined for the blackhole.
return;
}
if (m_sipChannels.Count == 0)
{
throw new ApplicationException("No channels are configured in the SIP transport layer. The request could not be sent.");
}
sipRequest.Header.ContentLength = (sipRequest.Body.NotNullOrBlank()) ? Encoding.UTF8.GetByteCount(sipRequest.Body) : 0;
if (sipChannel.IsTLS)
{
sipChannel.Send(dstEndPoint.GetIPEndPoint(), Encoding.UTF8.GetBytes(sipRequest.ToString()), sipRequest.URI.Host);
}
else
{
sipChannel.Send(dstEndPoint.GetIPEndPoint(), Encoding.UTF8.GetBytes(sipRequest.ToString()));
}
if (SIPRequestOutTraceEvent != null)
{
FireSIPRequestOutTraceEvent(sipChannel.SIPChannelEndPoint, dstEndPoint, sipRequest);
}
}
catch (ApplicationException appExcp)
{
logger.Warn("ApplicationException SIPTransport SendRequest. " + appExcp.Message);
SIPResponse errorResponse = GetResponse(sipRequest, SIPResponseStatusCodesEnum.InternalServerError, appExcp.Message);
// Remove any Via headers, other than the last one, that are for sockets hosted by this process.
while (errorResponse.Header.Vias.Length > 0)
{
if (IsLocalSIPEndPoint(SIPEndPoint.ParseSIPEndPoint(errorResponse.Header.Vias.TopViaHeader.ReceivedFromAddress)))
{
errorResponse.Header.Vias.PopTopViaHeader();
}
else
{
break;
}
}
if (errorResponse.Header.Vias.Length == 0)
{
logger.Warn("Could not send error response for " + appExcp.Message + " as no non-local Via headers were available.");
}
else
{
SendResponse(errorResponse);
}
}
}
示例6: SIPTCPMessageReceived
private void SIPTCPMessageReceived(SIPChannel channel, SIPEndPoint remoteEndPoint, byte[] buffer)
{
if (m_connectionFailures.ContainsKey(remoteEndPoint.GetIPEndPoint().ToString()))
{
m_connectionFailures.Remove(remoteEndPoint.GetIPEndPoint().ToString());
}
if (m_connectionFailureStrikes.ContainsKey(remoteEndPoint.GetIPEndPoint().ToString()))
{
m_connectionFailureStrikes.Remove(remoteEndPoint.GetIPEndPoint().ToString());
}
if (SIPMessageReceived != null)
{
SIPMessageReceived(channel, remoteEndPoint, buffer);
}
}
示例7: SIPURI
public SIPURI(SIPSchemesEnum scheme, SIPEndPoint sipEndPoint)
{
Scheme = scheme;
Host = sipEndPoint.GetIPEndPoint().ToString();
if (sipEndPoint.Protocol != SIPProtocolsEnum.udp)
{
Parameters.Set(m_uriParamTransportKey, sipEndPoint.Protocol.ToString());
}
}
示例8: AckRecognitionUnitTest
public void AckRecognitionUnitTest()
{
SIPTransport clientTransport = null;
SIPTransport serverTransport = null;
try
{
SIPTransactionEngine clientEngine = new SIPTransactionEngine(); // Client side of the INVITE.
SIPEndPoint clientEndPoint = new SIPEndPoint(SIPProtocolsEnum.udp, new IPEndPoint(IPAddress.Loopback, 12013));
clientTransport = new SIPTransport(MockSIPDNSManager.Resolve, clientEngine, new SIPUDPChannel(clientEndPoint.GetIPEndPoint()), false);
SetTransportTraceEvents(clientTransport);
SIPTransactionEngine serverEngine = new SIPTransactionEngine(); // Server side of the INVITE.
UASInviteTransaction serverTransaction = null;
SIPEndPoint serverEndPoint = new SIPEndPoint(new IPEndPoint(IPAddress.Loopback, 12014));
serverTransport = new SIPTransport(MockSIPDNSManager.Resolve, serverEngine, new SIPUDPChannel(serverEndPoint.GetIPEndPoint()), false);
SetTransportTraceEvents(serverTransport);
serverTransport.SIPTransportRequestReceived += (localEndPoint, remoteEndPoint, sipRequest) =>
{
Console.WriteLine("Server Transport Request In: " + sipRequest.Method + ".");
serverTransaction = serverTransport.CreateUASTransaction(sipRequest, remoteEndPoint, localEndPoint, null);
SetTransactionTraceEvents(serverTransaction);
serverTransaction.GotRequest(localEndPoint, remoteEndPoint, sipRequest);
};
SIPURI dummyURI = SIPURI.ParseSIPURI("sip:[email protected]" + serverEndPoint);
SIPRequest inviteRequest = GetDummyINVITERequest(dummyURI);
inviteRequest.LocalSIPEndPoint = clientTransport.GetDefaultTransportContact(SIPProtocolsEnum.udp);
// Send the invite to the server side.
UACInviteTransaction clientTransaction = new UACInviteTransaction(clientTransport, inviteRequest, serverEndPoint, clientEndPoint, null);
SetTransactionTraceEvents(clientTransaction);
clientEngine.AddTransaction(clientTransaction);
clientTransaction.SendInviteRequest(serverEndPoint, inviteRequest);
Thread.Sleep(500);
Assert.IsTrue(clientTransaction.TransactionState == SIPTransactionStatesEnum.Completed, "Client transaction in incorrect state.");
Assert.IsTrue(serverTransaction.TransactionState == SIPTransactionStatesEnum.Confirmed, "Server transaction in incorrect state.");
}
finally
{
if (clientTransport != null)
{
clientTransport.Shutdown();
}
if (serverTransport != null)
{
serverTransport.Shutdown();
}
}
}