/** * Send a message to a specified address. * * @param message Pre-formatted message to send. * @param receiverAddress Address to send it to. * @param receiverPort Receiver port. * @throws IOException If there is a problem connecting or sending. */ public void sendMessage( byte message[], InetAddress receiverAddress, int receiverPort, boolean retry) throws IOException { if (message == null || receiverAddress == null) throw new IllegalArgumentException("Null argument"); SSLSocket sock = (SSLSocket) this.stack.ioHandler.sendBytes(receiverAddress, receiverPort, "TLS", message, retry); // // Created a new socket so close the old one and s // Check for null (bug fix sent in by Christophe) if (sock != mySock && sock != null) { try { if (mySock != null) mySock.close(); } catch (IOException ex) { /* ignore */ } mySock = sock; this.myClientInputStream = mySock.getInputStream(); this.myClientOutputStream = mySock.getOutputStream(); // start a new reader on this end of the pipe. Thread mythread = new Thread(this); mythread.setDaemon(true); mythread.setName("TLSMessageChannelThread"); mythread.start(); } }
/** * Constructor - takes a datagram packet and a stack structure Extracts the address of the other * from the datagram packet and stashes away the pointer to the passed stack structure. * * @param stack is the shared SIPStack structure * @param messageProcessor is the creating message processor. */ protected UDPMessageChannel(SIPTransactionStack stack, UDPMessageProcessor messageProcessor) { super.messageProcessor = messageProcessor; this.sipStack = stack; Thread mythread = new Thread(this); this.myAddress = messageProcessor.getIpAddress().getHostAddress(); this.myPort = messageProcessor.getPort(); mythread.setName("UDPMessageChannelThread"); mythread.setDaemon(true); mythread.start(); }
/** * Constructor. We create one of these in order to process an incoming message. * * @param stack is the SIP sipStack. * @param messageProcessor is the creating message processor. * @param packet is the incoming datagram packet. */ protected UDPMessageChannel( SIPTransactionStack stack, UDPMessageProcessor messageProcessor, DatagramPacket packet) { this.incomingPacket = packet; super.messageProcessor = messageProcessor; this.sipStack = stack; this.myAddress = messageProcessor.getIpAddress().getHostAddress(); this.myPort = messageProcessor.getPort(); Thread mythread = new Thread(this); mythread.setDaemon(true); mythread.start(); }
/** Re Initialize the stack instance. */ protected void reInit() { super.reInit(); clientTransactions = Collections.synchronizedList(new ArrayList<SIPClientTransaction>()); serverTransactions = Collections.synchronizedList(new ArrayList<SIPServerTransaction>()); pendingTransactions = new HashSet<SIPServerTransaction>(); pendingRecords = Collections.synchronizedList(new ArrayList<PendingRecord>()); clientTransactionTable = new Hashtable<String, SIPTransaction>(); serverTransactionTable = new Hashtable<String, SIPTransaction>(); // Dialog dable. this.dialogTable = new Hashtable<String, SIPDialog>(); this.timer = new Timer(); pendingRecordScanner = new Thread(new PendingRecordScanner(this)); pendingRecordScanner.setDaemon(true); pendingRecordScanner.setName("PendingRecordScanner"); pendingRecordScanner.start(); }
/** * Send message to whoever is connected to us. Uses the topmost via address to send to. * * @param msg is the message to send. * @param retry */ private void sendMessage(byte[] msg, boolean retry) throws IOException { SSLSocket sock = (SSLSocket) this.stack.ioHandler.sendBytes( this.peerAddress, this.peerPort, this.peerProtocol, msg, retry); // Created a new socket so close the old one and stick the new // one in its place but dont do this if it is a datagram socket. // (could have replied via udp but received via tcp!). if (sock != mySock && sock != null) { try { if (mySock != null) mySock.close(); } catch (IOException ex) { } mySock = sock; this.myClientInputStream = mySock.getInputStream(); this.myClientOutputStream = mySock.getOutputStream(); Thread thread = new Thread(this); thread.setDaemon(true); thread.setName("TLSMessageChannelThread"); thread.start(); } }
/** * Constructor - gets called from the SIPStack class with a socket on accepting a new client. All * the processing of the message is done here with the stack being freed up to handle new * connections. The sock input is the socket that is returned from the accept. Global data that is * shared by all threads is accessible in the Server structure. * * @param sock Socket from which to read and write messages. The socket is already connected (was * created as a result of an accept). * @param sipStack Ptr to SIP Stack */ protected TLSMessageChannel( SSLSocket sock, SIPMessageStack sipStack, TLSMessageProcessor msgProcessor) throws IOException { if (LogWriter.needsLogging) { sipStack.logWriter.logMessage("creating new TLSMessageChannel "); sipStack.logWriter.logStackTrace(); } mySock = sock; peerAddress = mySock.getInetAddress(); myAddress = sipStack.getHostAddress(); myClientInputStream = mySock.getInputStream(); myClientOutputStream = mySock.getOutputStream(); mythread = new Thread(this); mythread.setDaemon(true); mythread.setName("TLSMessageChannelThread"); // Stash away a pointer to our stack structure. stack = sipStack; this.tlsMessageProcessor = msgProcessor; this.myPort = this.tlsMessageProcessor.getPort(); // Bug report by Vishwashanti Raj Kadiayl super.messageProcessor = msgProcessor; // Can drop this after response is sent potentially. mythread.start(); }