com.pkrete.jsip2.connection
Class SIP2SocketConnection

java.lang.Object
  extended by com.pkrete.jsip2.connection.SIP2SocketConnection

public class SIP2SocketConnection
extends Object

This class is responsible of the communication between the system and the ILS SIP server. The communication is based on a socket connection, which means that the data is sent and received by using a socket. The connection between the system and the ILS is stateless, and its based on message/reponse pairs. Each pair should stand on its own, irrespoective of any previous or future pair. However, in practise there are depencies between the message pairs. For example, in most cases the system must first log in to the ILS SIP server before sending any other messages.

Author:
Petteri Kivimäki

Constructor Summary
SIP2SocketConnection(String host, int port)
          Constructs and initializes a new SIP2SocketConnection object with the given host and port.
SIP2SocketConnection(String host, int port, int timeout)
          Constructs and initializes a new SIP2SocketConnection object with the given host, port and timeout.
 
Method Summary
 boolean close()
          Closes the connection to the ILS SIP server.
 boolean connect()
          Connects to the ILS SIP server.
 boolean connected()
          Returns true if and only if the socket is connected to a server.
 Socket getSocket()
          Returns the socket used for the connection with the ILS SIP server.
 String read()
          Read a line of text.
 SIP2MessageResponse send(SIP2MessageRequest request)
          Sends the given SIP2MessageRequest to the ILS SIP server and returns the SIP2MessageResponse received.
 void setSocket(Socket socket)
          Sets the used for the connection with the ILS SIP server.
 boolean write(String data)
          Sends the given string to the ILS SIP server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SIP2SocketConnection

public SIP2SocketConnection(String host,
                            int port)
Constructs and initializes a new SIP2SocketConnection object with the given host and port. The default timeout is 10 seconds.

Parameters:
host - address of the ILS SIP server
port - port number of the ILS SIP server

SIP2SocketConnection

public SIP2SocketConnection(String host,
                            int port,
                            int timeout)
Constructs and initializes a new SIP2SocketConnection object with the given host, port and timeout. A timeout of zero is interpreted as an infinite timeout.

Parameters:
host - address of the ILS SIP server
port - port number of the ILS SIP server
timeout - timeout value in milliseconds
Method Detail

connect

public boolean connect()
Connects to the ILS SIP server. The connection blocks until established or an error occurs.

Returns:
true if the socket successfuly connected to a server

close

public boolean close()
Closes the connection to the ILS SIP server.

Returns:
true if the socket has been closed

write

public boolean write(String data)
Sends the given string to the ILS SIP server.

Parameters:
data - string to be sent
Returns:
true if the operation succeeded

read

public String read()
Read a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed. The connection blocks until there's data available in the socket.

Returns:
A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached

send

public SIP2MessageResponse send(SIP2MessageRequest request)
                         throws InvalidSIP2ResponseException,
                                InvalidSIP2ResponseValueException
Sends the given SIP2MessageRequest to the ILS SIP server and returns the SIP2MessageResponse received. The connection blocks until the response is received or an error occurs.

Parameters:
request - SIP2MessageRequest to be sent
Returns:
SIP2MessageResponse received from the ILS SIP server
Throws:
InvalidSIP2ResponseException
InvalidSIP2ResponseValueException

connected

public boolean connected()
Returns true if and only if the socket is connected to a server.

Returns:
true if the socket is connected to a server, otherwise false

getSocket

public Socket getSocket()
Returns the socket used for the connection with the ILS SIP server.

Returns:
socket used for the connection with the ILS SIP server

setSocket

public void setSocket(Socket socket)
Sets the used for the connection with the ILS SIP server.

Parameters:
socket - new socket


Copyright © 2012-2014. All Rights Reserved.