/** When TcpConnection terminates. */ public void onConnectionTerminated(TcpConnection tcp_conn, Exception error) { if (listener != null) listener.onTransportTerminated(this, error); TcpSocket socket = tcp_conn.getSocket(); if (socket != null) try { socket.close(); } catch (Exception e) { } this.tcp_conn = null; this.listener = null; }
/** When new data is received through the TcpConnection. */ public void onReceivedData(TcpConnection tcp_conn, byte[] data, int len) { last_time = System.currentTimeMillis(); text += new String(data, 0, len); SipParser par = new SipParser(text); Message msg = par.getSipMessage(); while (msg != null) { // System.out.println("DEBUG: message len: "+msg.getLength()); msg.setRemoteAddress(tcp_conn.getRemoteAddress().toString()); msg.setRemotePort(tcp_conn.getRemotePort()); msg.setTransport(PROTO_TCP); msg.setConnectionId(connection_id); if (listener != null) listener.onReceivedMessage(this, msg); text = par.getRemainingString(); // System.out.println("DEBUG: text left: "+text.length()); par = new SipParser(text); msg = par.getSipMessage(); } }