peerbase.socket
Interface SocketInterface

All Known Implementing Classes:
NormalSocket

public interface SocketInterface

The socket interface for the PeerBase system. Methods for reading and writing are modelled after the basic InputStream/OutputStream classes of the Java library.

Author:
Nadeem Abdul Hamid

Method Summary
 void close()
          Closes this connection and releases any system resources associated with the socket.
 int read()
          Reads the next byte of data from the socket connection.
 int read(byte[] b)
          Reads some number of bytes from the socket connection and stores them into the buffer array b.
 void write(byte[] b)
          Writes b.length bytes from the specified byte array to this socket connection.
 

Method Detail

write

void write(byte[] b)
           throws java.io.IOException
Writes b.length bytes from the specified byte array to this socket connection.

Parameters:
b - the data
Throws:
java.io.IOException - if an I/O error occurs

read

int read()
         throws java.io.IOException
Reads the next byte of data from the socket connection. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the input has been reached, the value -1 is returned. This method blocks until input data is available, the end of the input is detected, or an exception is thrown.

Returns:
the next byte of data, or -1 if the end of the input is reached
Throws:
java.io.IOException - if an I/O error occurs

read

int read(byte[] b)
         throws java.io.IOException
Reads some number of bytes from the socket connection and stores them into the buffer array b. The number of bytes actually read is returned as an integer. This method blocks until input data is available, end of file is detected, or an exception is thrown.

Parameters:
b - the buffer into which the data is read
Returns:
the total number of bytes read into the buffer, or -1 if there is no more data because the end of the input has been reached
Throws:
java.io.IOException - if an I/O error occurs
See Also:
InputStream#read()

close

void close()
           throws java.io.IOException
Closes this connection and releases any system resources associated with the socket.

Throws:
java.io.IOException - if an I/O error occurs