Reference+
Class Name
Client
Description
A client connects to a server and sends data back and forth. If anything goes wrong with the connection, for example the host is not there or is listening on a different port, an exception is thrown.
Examples
import processing.net.*; Client myClient; int dataIn; void setup() { size(200, 200); // Connect to the local machine at port 5204. // This example will not run if you haven't // previously started a server on this port. myClient = new Client(this, "127.0.0.1", 5204); } void draw() { if (myClient.available() > 0) { dataIn = myClient.read(); } background(dataIn); }
Constructors
Client(parent, host, port)
Client(parent, socket)
Parameters
parent
(PApplet)
typically use "this"host
(String)
address of the serverport
(int)
port to read/write from on the serversocket
(Socket)
any object of type Socket
Methods
stop()
Disconnects from the serveractive()
Returns true if this client is still activeip()
Returns the IP address of the machine as a Stringavailable()
Returns the number of bytes in the buffer waiting to be readclear()
Clears the bufferread()
Returns a value from the bufferreadChar()
Returns the next byte in the buffer as a charreadBytes()
Reads a group of bytes from the bufferreadBytesUntil()
Reads from the buffer of bytes up to and including a particular characterreadString()
Returns the buffer as a StringreadStringUntil()
Returns the buffer as a String up to and including a particular characterwrite()
Writes bytes, chars, ints, bytes[], Strings
Related
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.