Skip to content

Commit 030f343

Browse files
committed
Update document commentary
1 parent 1cb08f4 commit 030f343

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

src/main/java/com/genonbeta/CoolSocket/CoolSocket.java

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ public CoolSocket()
5252

5353
/**
5454
* Creates a CoolSocket instance that will be available to the local machine.
55-
* @param port Port that CoolSocket will run on. A neutral zero would mean any port that is available.
5655
* @see CoolSocket#setSocketAddress(SocketAddress)
56+
* @param port Port that CoolSocket will run on. A neutral zero would mean any port that is available.
5757
*/
5858
public CoolSocket(int port)
5959
{
@@ -62,9 +62,9 @@ public CoolSocket(int port)
6262

6363
/**
6464
* Creates a CoolSocket instance that will be available to an address range.
65+
* @see CoolSocket#setSocketAddress(SocketAddress)
6566
* @param address IPv4 address for network interface.
6667
* @param port Port that CoolSocket will run on. A neutral zero would mean any port that is available.
67-
* @see CoolSocket#setSocketAddress(SocketAddress)
6868
*/
6969
public CoolSocket(String address, int port)
7070
{
@@ -114,7 +114,7 @@ public void run()
114114
}
115115

116116
/**
117-
* Counts the total connection of a client to the CoolSocket.
117+
* Counts the total connection of a client to the CoolSocket server.
118118
* @param address Client address.
119119
* @return The total number of connections.
120120
*/
@@ -155,6 +155,8 @@ public ExecutorService getExecutor()
155155

156156
/**
157157
* This should not be called before the {@link CoolSocket#start()} is called.
158+
* If the server was started with random port, this returns the port
159+
* assigned to the server.
158160
* @return The port that the server is running on.
159161
*/
160162
public int getLocalPort()
@@ -179,8 +181,9 @@ protected Thread getServerThread()
179181
}
180182

181183
/**
182-
* The socket address to run the server socket.
183-
* @return The original instance of the socket address.
184+
* This returns the socket address that is used to run the server.
185+
* @return Null if nothing was assigned before the original instance
186+
* of the socket address.
184187
*/
185188
public SocketAddress getSocketAddress()
186189
{
@@ -196,7 +199,8 @@ protected ServerRunnable getSocketRunnable()
196199
}
197200

198201
/**
199-
* The timeout before the server gives up waiting for receiving or sending the response.
202+
* Returns The timeout defines the time before the server gives up waiting for receiving or sending the
203+
* response.
200204
* @return The timeout in millisecond. If not defined previously, it might be {@link CoolSocket#NO_TIMEOUT}.
201205
*/
202206
public int getSocketTimeout()
@@ -236,7 +240,8 @@ public boolean isServerAlive()
236240

237241
/**
238242
* When a client is connected, to not block the server thread, we call this method to communicate
239-
* with it.
243+
* with it. The socket is different from a normal socket connection where the data should also
244+
* contain a header.
240245
* @param socket The socket that is connected to the client.
241246
* @return True if the switching process to a child thread is successful.
242247
*/
@@ -438,8 +443,8 @@ public void onServerStopped()
438443
}
439444

440445
/**
441-
* This method will be called when the connection handling failed or something that was expected
442-
* happened.
446+
* This method will be called when the connection handling failed or something that was not
447+
* expected happened.
443448
* @param exception The error that occurred.
444449
*/
445450
public void onInternalError(Exception exception)
@@ -467,7 +472,8 @@ public ActiveConnection()
467472
/**
468473
* An instance that uses its own socket with a timeout. Call {@link ActiveConnection(Socket)}
469474
* with null argument if the socket will be provided later.
470-
* @param timeout Timeout that will limit the amount of time that the requests to complete.
475+
* @param timeout Timeout that will limit the amount of time that the requests to wait for
476+
* another packet to arrive or go.
471477
*/
472478
public ActiveConnection(int timeout)
473479
{
@@ -486,7 +492,8 @@ public ActiveConnection(Socket socket)
486492
/**
487493
* An instance with timeout and socket connection to a CoolSocket server.
488494
* @param socket The connection to CoolSocket server or client.
489-
* @param timeout Timeout that will limit the amount of time that the requests to complete.
495+
* @param timeout Timeout that will limit the amount of time that the requests to wait for
496+
* another packet to arrive or go.
490497
*/
491498
public ActiveConnection(Socket socket, int timeout)
492499
{
@@ -550,7 +557,7 @@ public String getClientAddress()
550557
}
551558

552559
/**
553-
* A proposed method to determine a connection with its instance.
560+
* A proposed method to determine a connection with a unique id.
554561
* @see ActiveConnection#setId(int)
555562
* @return The class id defined during creation of this instance of the class.
556563
*/
@@ -579,8 +586,8 @@ public int getTimeout()
579586
}
580587

581588
/**
582-
* This method use {@link Object#toString()} method which will return the
583-
* unique id to this instance of the class to determine whether they are the same instance.
589+
* This uses {@link Object#toString()} method which will return the unique id to this instance of
590+
* the class to determine whether they are the same instance.
584591
* @param obj An instance of this class is expected and if not then the parent class will handle it.
585592
* @return True if the two object is the same.
586593
*/
@@ -594,10 +601,8 @@ public boolean equals(Object obj)
594601
* When the opposite side calls {@link ActiveConnection#reply(String)}, this method should
595602
* be invoked so that the communication occurs. The order of the calls should be in order
596603
* with their peers. For instance, when you call {@link ActiveConnection#reply(String)} method,
597-
* the other side should already have called this method or vice versa, which means
598-
* asynchronous task should not block the thread or any other works should only be with
599-
* the other side. To overcome this, you can {@link ActiveConnection#setTimeout(int)}
600-
* with {@link CoolSocket#NO_TIMEOUT} which will make it wait indefinitely.
604+
* the other side should already have called this method or vice versa, which means asynchronous
605+
* task should not block the thread when the data is being transferred.
601606
* @see ActiveConnection#reply(String)
602607
* @return The response that is received.
603608
* @throws IOException When a socket IO error occurs.
@@ -636,7 +641,7 @@ public Response receive() throws IOException, TimeoutException, JSONException
636641
response.headerIndex = headerJSON;
637642

638643
if (headerEndPoint < headerIndex.size())
639-
// For the bytes are transferred as they come, we might exceed the
644+
// When the bytes are transferred as they come, we might exceed the
640645
// point where the header ends. If it is the case, then we trim the
641646
// header and the response accordingly
642647
receivedMessage.write(headerString.substring(headerEndPoint + (HEADER_SEPARATOR.length())).getBytes());

0 commit comments

Comments
 (0)