|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjist.swans.trans.TcpSocket
public class TcpSocket
SWANS Implementation of Socket entity.
Nested Class Summary | |
---|---|
static class |
TcpSocket.TcpSocketCallback
Implementation of Socket Callback for TcpSocket. |
Nested classes/interfaces inherited from interface jist.swans.trans.SocketInterface |
---|
SocketInterface.TcpServerSocketInterface, SocketInterface.TcpSocketInterface |
Field Summary | |
---|---|
static long |
DELAYED_ACK_TIME
Number of milliseconds to wait before sending an ACK. |
static int |
FULL_DEBUG
Debug printing flag. |
static int |
INFO
Debug printing flag. |
static short |
INIT_WINDOW_SIZE
Initial window size. |
static int |
MSL
Maximum Segment Lifetime. |
static int |
MSS
Maximum Segment Size. |
static int |
OFF
Debug printing flag. |
static long |
PERSIST_TIMER
Number of seconds to wait before sending probe packets. |
static int |
PRINTOUT
Indicator for printing debug outputs. |
static long |
RETRANSMIT_TIMEOUT
Number of seconds to wait for first retransmission timer. |
static long |
RETRANSMIT_TIMEOUT_FINAL
Number of seconds to wait for second retransmission timer. |
static int |
TCP_DEBUG
Debug printing flag. |
Constructor Summary | |
---|---|
|
TcpSocket()
Creates an unconnected socket, with the system-default type of SocketImpl. |
|
TcpSocket(java.net.InetAddress address,
int port)
Creates a stream socket and connects it to the specified port number at the specified IP address. |
|
TcpSocket(java.net.InetAddress host,
int port,
boolean stream)
Deprecated. |
|
TcpSocket(java.net.InetAddress address,
int port,
java.net.InetAddress localAddr,
int localPort)
Creates a socket and connects it to the specified remote address on the specified remote port. |
protected |
TcpSocket(java.net.SocketImpl impl)
Creates an unconnected Socket with a user-specified SocketImpl. |
|
TcpSocket(java.lang.String host,
int port)
Creates a stream socket and connects it to the specified port number on the named host. |
|
TcpSocket(java.lang.String host,
int port,
boolean stream)
Deprecated. |
|
TcpSocket(java.lang.String host,
int port,
java.net.InetAddress localAddr,
int localPort)
Creates a socket and connects it to the specified remote host on the specified remote port. |
protected |
TcpSocket(TransInterface.TransTcpInterface tcpEntity,
java.net.InetAddress rAddr,
short rPort,
java.net.InetAddress lAddr,
short lPort,
int initialAckNum,
short winSize)
Creates an unconnected Socket with a user-specified TransInterface Entity and SYN packet received by TcpServerSocket. |
Method Summary | |
---|---|
void |
_jistPostInit()
Post-constructor call. |
void |
bind(java.net.SocketAddress bindpoint)
Binds the ServerSocket to a specific address (IP address and port number). |
void |
checkPacketandState(TransTcp.TcpMessage msg,
NetAddress src)
Check and process the incoming packet depending on current state of the socket. |
void |
close()
Closes this socket. |
void |
connect(java.net.SocketAddress endpoint)
Connects this socket to the server. |
void |
connect(java.net.SocketAddress endpoint,
int timeout)
Connects this socket to the server with a specified timeout value. |
void |
constructPackets()
Creates packets to be sent based on the receiver's advertised window (managing flow control). |
void |
createProxy()
Create an entity reference to itself. |
protected void |
establishingConnection()
this method is used to wait for incoming ACK packet for connection establishment. |
byte[] |
getBytesFromSocket(int length)
This method is called by the input stream to retrieve data from the transport layer. |
java.nio.channels.SocketChannel |
getChannel()
Returns the unique SocketChannel object associated with this socket, if any. |
java.net.InetAddress |
getInetAddress()
Returns the local address of this server socket/socket. |
InputStream |
getInputStream()
Returns an input stream for this socket. |
boolean |
getKeepAlive()
Tests if SO_KEEPALIVE is enabled. |
java.net.InetAddress |
getLocalAddress()
Gets the local address to which the socket is bound. |
int |
getLocalPort()
Returns the port on which this socket is listening. |
java.net.SocketAddress |
getLocalSocketAddress()
Returns the address of the endpoint this socket is bound to, or null if it is not bound yet. |
boolean |
getOOBInline()
Tests if OOBINLINE is enabled. |
OutputStream |
getOutputStream()
Returns an output stream for this socket. |
int |
getPort()
Returns the remote port to which this socket is connected. |
SocketInterface.TcpSocketInterface |
getProxy()
Returns the entity reference to the socket itself. |
int |
getReceiveBufferSize()
Gets the value of the SO_RCVBUF option for this ServerSocket, that is the proposed buffer size that will be used for Sockets accepted from this ServerSocket. |
java.net.SocketAddress |
getRemoteSocketAddress()
Returns the address of the endpoint this socket is connected to, or null if it is unconnected. |
boolean |
getReuseAddress()
Tests if SO_REUSEADDR is enabled. |
int |
getSendBufferSize()
Get value of the SO_SNDBUF option for this Socket, that is the buffer size used by the platform for output on this Socket. |
int |
getSoLinger()
Returns setting for SO_LINGER. |
int |
getSoTimeout()
Retrieve setting for SO_TIMEOUT. |
boolean |
getTcpNoDelay()
Tests if TCP_NODELAY is enabled. |
int |
getTrafficClass()
Gets traffic class or type-of-service in the IP header for packets sent from this Socket. |
boolean |
isBound()
Returns the binding state of the ServerSocket. |
boolean |
isClosed()
Returns the closed state of the ServerSocket. |
boolean |
isConnected()
Returns the connection state of the socket. |
boolean |
isInputShutdown()
Returns wether the read-half of the socket connection is closed. |
boolean |
isOutputShutdown()
Returns wether the write-half of the socket connection is closed. |
void |
persistTimerTimeout(int timerId,
int seqNum)
Execution when persist timer times out (sending probe message). |
protected void |
printMessage(TransTcp.TcpMessage msg,
boolean isReceive)
Prints out the message header and payload. |
int |
queueBytes(byte[] data)
This method is called to send bytes to the other side. |
void |
resetTimerTimeout(int timerId)
Execution when reset timer times out (closing the socket). |
void |
retransmitTimerTimeout(int seqNum,
long time)
Attempt to retransmit because the timer times out. |
protected TransTcp.TcpMessage |
sendDataPacket(byte[] data)
Send a packet to the remote socket. |
protected void |
sendFINPacket()
A method to send FIN packet. |
protected void |
sendFirstACKPacket()
A method to send ACK packet. |
protected void |
sendRSTPacket(int seqNum,
int ackNum)
A method to send RST packet. |
protected void |
sendSYNACKPacket()
A method to send SYNACK packet. |
protected void |
sendSYNPacket()
A method to send SYN packet. |
void |
sendUrgentData(int data)
Send one byte of urgent data on the socket. |
void |
setKeepAlive(boolean on)
Enable/disable SO_KEEPALIVE. |
void |
setOOBInline(boolean on)
Enable/disable OOBINLINE (receipt of TCP urgent data) By default, this option is disabled and TCP urgent data received on a socket is silently discarded. |
void |
setReceiveBufferSize(int size)
Sets a default proposed value for the SO_RCVBUF option for sockets accepted from this ServerSocket. |
void |
setReuseAddress(boolean on)
Enable/disable the SO_REUSEADDR socket option. |
void |
setSendBufferSize(int size)
Sets the SO_SNDBUF option to the specified value for this Socket. |
static void |
setSocketImplFactory(java.net.SocketImplFactory fac)
Sets the client socket implementation factory for the application. |
void |
setSoLinger(boolean on,
int linger)
Enable/disable SO_LINGER with the specified linger time in seconds. |
void |
setSoTimeout(int timeout)
Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds. |
void |
setTcpEntity(TransInterface.TransTcpInterface tcpEntity)
Sets the reference to the network layer. |
void |
setTcpNoDelay(boolean on)
Enable/disable TCP_NODELAY (disable/enable Nagle's algorithm). |
void |
setTrafficClass(int tc)
Sets traffic class or type-of-service octet in the IP header for packets sent from this Socket. |
void |
shutdownInput()
Places the input stream for this socket at "end of stream". |
void |
shutdownOutput()
Disables the output stream for this socket. |
void |
startPersistTimer(int seqNum)
Methods for persist timer (sender sending packets to probe receiver window). |
void |
startResetTimer()
Methods for reset timer (this timer is used when establishing or closing connection --> If no reply is received, connection is reset). |
void |
startRetransmitTimer(int seqNum,
long time)
Schedule a retransmission for a message. |
void |
startTimeWaitTimer()
Methods for timer during TIME_WAIT state. |
void |
timeWaitTimerTimeout()
Execution when time wait timer times out (closing the socket). |
java.lang.String |
toString()
Returns the implementation address and implementation port of this socket as a String. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int OFF
public static final int INFO
public static final int TCP_DEBUG
public static final int FULL_DEBUG
public static final int PRINTOUT
public static final int MSS
public static final int MSL
public static final long DELAYED_ACK_TIME
public static final long RETRANSMIT_TIMEOUT
public static final long RETRANSMIT_TIMEOUT_FINAL
public static final long PERSIST_TIMER
public static final short INIT_WINDOW_SIZE
Constructor Detail |
---|
public TcpSocket()
public TcpSocket(java.net.InetAddress address, int port)
address
- the IP addressport
- the port numberpublic TcpSocket(java.net.InetAddress host, int port, boolean stream)
host
- the IP addressport
- the port numberstream
- if true, create a stream socket;
otherwise, create a datagram socket.public TcpSocket(java.net.InetAddress address, int port, java.net.InetAddress localAddr, int localPort)
address
- the remote addressport
- the remote portlocalAddr
- the local address the socket is bound tolocalPort
- the local port the socket is bound toprotected TcpSocket(java.net.SocketImpl impl)
impl
- an instance of a SocketImpl the subclass wishes to use on the Socketprotected TcpSocket(TransInterface.TransTcpInterface tcpEntity, java.net.InetAddress rAddr, short rPort, java.net.InetAddress lAddr, short lPort, int initialAckNum, short winSize)
tcpEntity
- entity reference to transport layerrAddr
- remote addressrPort
- remote port numberlAddr
- local addresslPort
- local port numberinitialAckNum
- initial acknowledgement numberwinSize
- the other side's receiver window sizepublic TcpSocket(java.lang.String host, int port)
host
- the host name, or null for the loopback address.port
- the port number.public TcpSocket(java.lang.String host, int port, boolean stream)
host
- the host name, or null for the loopback address.port
- the port number.stream
- a boolean indicating whether this is
a stream socket or a datagram socket.public TcpSocket(java.lang.String host, int port, java.net.InetAddress localAddr, int localPort)
host
- the name of the remote host, or null for the loopback address.port
- the remote portlocalAddr
- the local address the socket is bound tolocalPort
- the local port the socket is bound toMethod Detail |
---|
public void createProxy()
public SocketInterface.TcpSocketInterface getProxy()
public void setTcpEntity(TransInterface.TransTcpInterface tcpEntity)
setTcpEntity
in interface SocketInterface
tcpEntity
- entity reference to transport layerpublic void _jistPostInit()
_jistPostInit
in interface SocketInterface
public void bind(java.net.SocketAddress bindpoint)
bind
in interface SocketInterface
bindpoint
- The IP address & port number to bind to.public void close()
close
in interface SocketInterface
public void connect(java.net.SocketAddress endpoint)
connect
in interface SocketInterface.TcpSocketInterface
endpoint
- the SocketAddresspublic void connect(java.net.SocketAddress endpoint, int timeout)
connect
in interface SocketInterface.TcpSocketInterface
endpoint
- the SocketAddresstimeout
- the timeout value to be used in millisecondspublic java.nio.channels.SocketChannel getChannel()
getChannel
in interface SocketInterface.TcpSocketInterface
public java.net.InetAddress getInetAddress()
getInetAddress
in interface SocketInterface
public InputStream getInputStream()
getInputStream
in interface SocketInterface.TcpSocketInterface
public boolean getKeepAlive()
getKeepAlive
in interface SocketInterface.TcpSocketInterface
public java.net.InetAddress getLocalAddress()
getLocalAddress
in interface SocketInterface.TcpSocketInterface
public int getLocalPort()
getLocalPort
in interface SocketInterface
public java.net.SocketAddress getLocalSocketAddress()
getLocalSocketAddress
in interface SocketInterface
public boolean getOOBInline()
getOOBInline
in interface SocketInterface.TcpSocketInterface
public OutputStream getOutputStream()
getOutputStream
in interface SocketInterface.TcpSocketInterface
public int getPort()
getPort
in interface SocketInterface.TcpSocketInterface
public int getReceiveBufferSize()
getReceiveBufferSize
in interface SocketInterface
public java.net.SocketAddress getRemoteSocketAddress()
getRemoteSocketAddress
in interface SocketInterface.TcpSocketInterface
public boolean getReuseAddress()
getReuseAddress
in interface SocketInterface
public int getSendBufferSize()
getSendBufferSize
in interface SocketInterface.TcpSocketInterface
public int getSoLinger()
getSoLinger
in interface SocketInterface.TcpSocketInterface
public int getSoTimeout()
getSoTimeout
in interface SocketInterface
public boolean getTcpNoDelay()
getTcpNoDelay
in interface SocketInterface.TcpSocketInterface
public int getTrafficClass()
getTrafficClass
in interface SocketInterface.TcpSocketInterface
public boolean isBound()
isBound
in interface SocketInterface
public boolean isClosed()
isClosed
in interface SocketInterface
public boolean isConnected()
isConnected
in interface SocketInterface.TcpSocketInterface
public boolean isInputShutdown()
isInputShutdown
in interface SocketInterface.TcpSocketInterface
public boolean isOutputShutdown()
isOutputShutdown
in interface SocketInterface.TcpSocketInterface
public void sendUrgentData(int data)
sendUrgentData
in interface SocketInterface.TcpSocketInterface
data
- The byte of data to sendpublic void setKeepAlive(boolean on)
setKeepAlive
in interface SocketInterface.TcpSocketInterface
on
- whether or not to have socket keep alive turned onpublic void setOOBInline(boolean on)
setOOBInline
in interface SocketInterface.TcpSocketInterface
on
- true to enable OOBINLINE, false to disable.public void setReceiveBufferSize(int size)
setReceiveBufferSize
in interface SocketInterface
size
- the size to which to set the receive buffer size.
This value must be greater than 0.public void setReuseAddress(boolean on)
setReuseAddress
in interface SocketInterface
on
- whether to enable or disable the socket optionpublic void setSendBufferSize(int size)
setSendBufferSize
in interface SocketInterface.TcpSocketInterface
size
- the size to which to set the send buffer size.
This value must be greater than 0.public static void setSocketImplFactory(java.net.SocketImplFactory fac)
fac
- the desired factorypublic void setSoLinger(boolean on, int linger)
setSoLinger
in interface SocketInterface.TcpSocketInterface
on
- whether or not to linger on.linger
- how long to linger for, if on is true.public void setSoTimeout(int timeout)
setSoTimeout
in interface SocketInterface
timeout
- the specified timeout, in millisecondspublic void setTcpNoDelay(boolean on)
setTcpNoDelay
in interface SocketInterface.TcpSocketInterface
on
- true to enable TCP_NODELAY, false to disable.public void setTrafficClass(int tc)
setTrafficClass
in interface SocketInterface.TcpSocketInterface
tc
- an int value for the bitset.public void shutdownInput() throws java.io.IOException
shutdownInput
in interface SocketInterface.TcpSocketInterface
java.io.IOException
- if an I/O error occurs when shutting down this socket.public void shutdownOutput() throws java.io.IOException
shutdownOutput
in interface SocketInterface.TcpSocketInterface
java.io.IOException
- if an I/O error occurs when shutting down this socket.public java.lang.String toString()
toString
in interface SocketInterface
toString
in class java.lang.Object
protected void establishingConnection()
protected void printMessage(TransTcp.TcpMessage msg, boolean isReceive)
msg
- TCP message to print outisReceive
- true if printing for receiving sideprotected void sendSYNPacket()
protected void sendSYNACKPacket()
protected void sendFirstACKPacket()
protected void sendFINPacket()
protected void sendRSTPacket(int seqNum, int ackNum)
seqNum
- sequence numberackNum
- acknowledgement numberprotected TransTcp.TcpMessage sendDataPacket(byte[] data)
data
- data to send
public void constructPackets()
constructPackets
in interface SocketInterface.TcpSocketInterface
public int queueBytes(byte[] data)
queueBytes
in interface SocketInterface.TcpSocketInterface
data
- bytes to be stored in the send buffer
public byte[] getBytesFromSocket(int length)
getBytesFromSocket
in interface SocketInterface.TcpSocketInterface
length
- number of bytes to retrieve
public void startRetransmitTimer(int seqNum, long time)
startRetransmitTimer
in interface SocketInterface.TcpSocketInterface
seqNum
- sequence number of message to retransmittime
- wait time before attempting to retransmitpublic void retransmitTimerTimeout(int seqNum, long time)
retransmitTimerTimeout
in interface SocketInterface.TcpSocketInterface
seqNum
- sequence number of message to retransmittime
- wait time before attempting to retransmitpublic void startPersistTimer(int seqNum)
startPersistTimer
in interface SocketInterface.TcpSocketInterface
seqNum
- number of the probe messagepublic void persistTimerTimeout(int timerId, int seqNum)
persistTimerTimeout
in interface SocketInterface.TcpSocketInterface
timerId
- ID of the persist timerseqNum
- number of the probe messagepublic void startResetTimer()
startResetTimer
in interface SocketInterface.TcpSocketInterface
public void resetTimerTimeout(int timerId)
resetTimerTimeout
in interface SocketInterface.TcpSocketInterface
timerId
- ID of the reset timerpublic void startTimeWaitTimer()
startTimeWaitTimer
in interface SocketInterface.TcpSocketInterface
public void timeWaitTimerTimeout()
timeWaitTimerTimeout
in interface SocketInterface.TcpSocketInterface
public void checkPacketandState(TransTcp.TcpMessage msg, NetAddress src)
checkPacketandState
in interface SocketInterface
msg
- the incoming TCP messagesrc
- source of packet
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |