Skip to content

Commit adfaed5

Browse files
committed
Basic 2.0 Ref changes
1 parent b099bbf commit adfaed5

File tree

5 files changed

+251
-188
lines changed

5 files changed

+251
-188
lines changed

java/libraries/net/src/processing/net/Client.java

Lines changed: 40 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,8 @@
3131
import java.net.*;
3232

3333
/**
34-
* A client connects to a server and sends data back and forth.
35-
* If anything goes wrong with the connection,
36-
* for example the host is not there or is listening on a different port,
37-
* an exception is thrown.
38-
*
39-
* @webref
34+
* @generate Client.xml
35+
* @webref net
4036
* @brief The client class is used to create client Objects which connect to a server to exchange data.
4137
* @instanceName client any variable of type Client
4238
* @usage Application
@@ -126,17 +122,10 @@ public Client(PApplet parent, Socket socket) throws IOException {
126122

127123

128124
/**
129-
* Disconnects from the server. Use to shut the connection when you're finished with the Client.
130-
* =advanced
131-
* Disconnect from the server and calls disconnectEvent(Client c)
132-
* in the host PApplet.
133-
* <P/>
134-
* Use this to shut the connection if you're finished with it
135-
* while your applet is still running. Otherwise, it will be
136-
* automatically be shut down by the host PApplet
137-
* (using dispose, which is identical)
138-
* @webref
125+
* @generate Client_stop.xml
126+
* @webref client:client
139127
* @brief Disconnects from the server
128+
* @usage application
140129
*/
141130
public void stop() {
142131
dispose();
@@ -230,18 +219,20 @@ public boolean active() {
230219

231220

232221
/**
233-
* Returns the IP address of the computer to which the Client is attached.
222+
* @generate Client_ip.xml
223+
* @webref client:client
224+
* @usage application
234225
* @brief Returns the IP address of the machine as a String
235-
* @webref
236226
*/
237227
public String ip() {
238228
return socket.getInetAddress().getHostAddress();
239229
}
240230

241231

242232
/**
243-
* Returns the number of bytes available. When any client has bytes available from the server, it returns the number of bytes.
244-
* @webref
233+
* @generate Client_available.xml
234+
* @webref client:client
235+
* @usage application
245236
* @brief Returns the number of bytes in the buffer waiting to be read
246237
*/
247238
public int available() {
@@ -250,9 +241,9 @@ public int available() {
250241

251242

252243
/**
253-
* Empty the buffer, removes all the data stored there.
254-
*
255-
* @webref
244+
* @generate Client_clear.xml
245+
* @webref client:client
246+
* @usage application
256247
* @brief Clears the buffer
257248
*/
258249
public void clear() {
@@ -262,10 +253,9 @@ public void clear() {
262253

263254

264255
/**
265-
* Returns a number between 0 and 255 for the next byte that's waiting in the buffer.
266-
* Returns -1 if there is no byte, although this should be avoided by first cheacking <b>available()</b> to see if any data is available.
267-
*
268-
* @webref
256+
* @generate Client_read.xml
257+
* @webref client:client
258+
* @usage application
269259
* @brief Returns a value from the buffer
270260
*/
271261
public int read() {
@@ -283,10 +273,9 @@ public int read() {
283273

284274

285275
/**
286-
* Returns the next byte in the buffer as a char.
287-
* Returns -1, or 0xffff, if nothing is there.
288-
*
289-
* @webref
276+
* @generate Client_readChar.xml
277+
* @webref client:client
278+
* @usage application
290279
* @brief Returns the next byte in the buffer as a char
291280
*/
292281
public char readChar() {
@@ -296,19 +285,15 @@ public char readChar() {
296285

297286

298287
/**
299-
* Reads a group of bytes from the buffer.
300-
* The version with no parameters returns a byte array of all data in the buffer.
301-
* This is not efficient, but is easy to use.
302-
* The version with the <b>byteBuffer</b> parameter is more memory and time efficient.
303-
* It grabs the data in the buffer and puts it into the byte array passed in and returns an int value for the number of bytes read.
304-
* If more bytes are available than can fit into the <b>byteBuffer</b>, only those that fit are read.
305-
* =advanced
288+
* @generate Client_readBytes.xml
289+
* <h3>Advanced</h3>
306290
* Return a byte array of anything that's in the serial buffer.
307291
* Not particularly memory/speed efficient, because it creates
308292
* a byte array on each read, but it's easier to use than
309293
* readBytes(byte b[]) (see below).
310294
*
311-
* @webref
295+
* @webref client:client
296+
* @usage application
312297
* @brief Reads everything in the buffer
313298
*/
314299
public byte[] readBytes() {
@@ -327,6 +312,7 @@ public byte[] readBytes() {
327312

328313

329314
/**
315+
* <h3>Advanced</h3>
330316
* Grab whatever is in the serial buffer, and stuff it into a
331317
* byte buffer passed in by the user. This is more memory/time
332318
* efficient than readBytes() returning a byte[] array.
@@ -356,14 +342,9 @@ public int readBytes(byte bytebuffer[]) {
356342

357343

358344
/**
359-
* Reads from the port into a buffer of bytes up to and including a particular character.
360-
* If the character isn't in the buffer, 'null' is returned.
361-
* The version with no <b>byteBuffer</b> parameter returns a byte array of all data up to and including the <b>interesting</b> byte.
362-
* This is not efficient, but is easy to use. The version with the <b>byteBuffer</b> parameter is more memory and time efficient.
363-
* It grabs the data in the buffer and puts it into the byte array passed in and returns an int value for the number of bytes read.
364-
* If the byte buffer is not large enough, -1 is returned and an error is printed to the message area. If nothing is in the buffer, 0 is returned.
365-
*
366-
* @webref
345+
* @generate Client_readBytesUntil.xml
346+
* @webref client:client
347+
* @usage application
367348
* @brief Reads from the buffer of bytes up to and including a particular character
368349
* @param interesting character designated to mark the end of the data
369350
*/
@@ -396,6 +377,7 @@ public byte[] readBytesUntil(int interesting) {
396377

397378

398379
/**
380+
* <h3>Advanced</h3>
399381
* Reads from the serial port into a buffer of bytes until a
400382
* particular character. If the character isn't in the serial
401383
* buffer, then 'null' is returned.
@@ -442,13 +424,9 @@ public int readBytesUntil(int interesting, byte byteBuffer[]) {
442424

443425

444426
/**
445-
* Returns the all the data from the buffer as a String.
446-
* This method assumes the incoming characters are ASCII.
447-
* If you want to transfer Unicode data,
448-
* first convert the String to a byte stream in the representation of your choice
449-
* (i.e. UTF8 or two-byte Unicode data), and send it as a byte array.
450-
*
451-
* @webref
427+
* @generate Client_readString.xml
428+
* @webref client:client
429+
* @usage application
452430
* @brief Returns the buffer as a String
453431
*/
454432
public String readString() {
@@ -458,14 +436,15 @@ public String readString() {
458436

459437

460438
/**
461-
* Combination of <b>readBytesUntil()</b> and <b>readString()</b>. Returns <b>null</b> if it doesn't find what you're looking for.
462-
* =advanced
439+
* @generate Client_readStringUntil.xml
440+
* <h3>Advanced</h3>
463441
* <p/>
464442
* If you want to move Unicode data, you can first convert the
465443
* String to a byte stream in the representation of your choice
466444
* (i.e. UTF8 or two-byte Unicode data), and send it as a byte array.
467445
*
468-
* @webref
446+
* @webref client:client
447+
* @usage application
469448
* @brief Returns the buffer as a String up to and including a particular character
470449
* @param interesting character designated to mark the end of the data
471450
*/
@@ -477,9 +456,9 @@ public String readStringUntil(int interesting) {
477456

478457

479458
/**
480-
* Writes data to a server specified when constructing the client.
481-
*
482-
* @webref
459+
* @generate Client_write.xml
460+
* @webref client:client
461+
* @usage application
483462
* @brief Writes bytes, chars, ints, bytes[], Strings
484463
* @param data data to write
485464
*/
@@ -515,6 +494,7 @@ public void write(byte data[]) {
515494

516495

517496
/**
497+
* <h3>Advanced</h3>
518498
* Write a String to the output. Note that this doesn't account
519499
* for Unicode (two bytes per char), nor will it send UTF8
520500
* characters.. It assumes that you mean to send a byte buffer

java/libraries/net/src/processing/net/Server.java

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,11 @@
3131
import java.net.*;
3232

3333
/**
34-
* A server sends and receives data to and from its associated clients (other programs connected to it).
35-
* When a server is started, it begins listening for connections on the port specified by the <b>port</b> parameter.
36-
* Computers have many ports for transferring data and some are commonly used so be sure to not select one of these.
37-
* For example, web servers usually use port 80 and POP mail uses port 110.
38-
*
39-
* @webref
34+
* @generate Server.xml
35+
* @webref net
36+
* @usage application
4037
* @brief The server class is used to create server objects which send and receives data to and from its associated clients (other programs connected to it).
4138
* @instanceName server any variable of type Server
42-
* @usage Application
4339
*/
4440
public class Server implements Runnable {
4541

@@ -95,8 +91,8 @@ public Server(PApplet parent, int port) {
9591

9692

9793
/**
98-
* Disconnect a particular client.
99-
* @webref
94+
* @generate Server_disconnect.xml
95+
* @webref server:server
10096
* @param client the client to disconnect
10197
*/
10298
public void disconnect(Client client) {
@@ -144,8 +140,9 @@ protected int clientIndex(Client client) {
144140
int lastAvailable = -1;
145141

146142
/**
147-
* Returns the next client in line with a new message
148-
* @webref
143+
* @generate Server_available.xml
144+
* @webref server
145+
* @usage application
149146
*/
150147
public Client available() {
151148
synchronized (clients) {
@@ -166,13 +163,14 @@ public Client available() {
166163

167164

168165
/**
169-
* Disconnects all clients and stops the server
170-
* =advanced
166+
* @generate Server_stop.xml
167+
* <h3>Advanced</h3>
171168
* <p/>
172169
* Use this to shut down the server if you finish using it while your applet
173170
* is still running. Otherwise, it will be automatically be shut down by the
174171
* host PApplet using dispose(), which is identical.
175-
* @webref
172+
* @webref server
173+
* @usage application
176174
*/
177175
public void stop() {
178176
dispose();
@@ -236,10 +234,8 @@ public void run() {
236234

237235

238236
/**
239-
* Write a value to all the connected clients.
240-
* See Client.write() for operational details.
241-
*
242-
* @webref
237+
* @generate Server_write.xml
238+
* @webref server
243239
* @brief Writes data to all connected clients
244240
* @param data data to write
245241
*/
@@ -255,11 +251,6 @@ public void write(int data) { // will also cover char
255251
}
256252
}
257253

258-
259-
/**
260-
* Write a byte array to all the connected clients.
261-
* See Client.write() for operational details.
262-
*/
263254
public void write(byte data[]) {
264255
int index = 0;
265256
while (index < clientCount) {
@@ -272,11 +263,6 @@ public void write(byte data[]) {
272263
}
273264
}
274265

275-
276-
/**
277-
* Write a String to all the connected clients.
278-
* See Client.write() for operational details.
279-
*/
280266
public void write(String data) {
281267
int index = 0;
282268
while (index < clientCount) {

0 commit comments

Comments
 (0)