public void sendResponse(SipResponse response, SipConnection connection) throws IOException
{
if (connection == null || !connection.getConnector().isReliable() || !connection.isOpen())
{
Via via = response.getTopVia();
SipConnector connector = null;
InetAddress address = null;
if (connection != null)
{
connector = connection.getConnector();
address = connection.getRemoteAddress();
}
else
{
int transport = SipConnectors.getOrdinal(via.getTransport());
address = InetAddress.getByName(via.getHost());
connector = findConnector(transport, address);
}
int port = -1;
String srport = via.getRport();
if (srport != null)
{
port = Integer.parseInt(srport);
}
else
{
port = via.getPort();
if (port == -1)
port = connection.getConnector().getDefaultPort();
}
connection = connector.getConnection(address, port);
}