 |
 |
 |
 |
Name |
|
beginNet() |
 |
|
|
Examples |
|
// Server
int port = 5204;
int bgColor = 0;
void setup()
{
// Starts a server on port 5204
beginNet(port);
}
void loop()
{
netWrite(Integer.toString(bgColor));
bgColor = bgColor + 1;
if (bgColor > 255) {
bgColor = 0;
}
}
|
|
// Client
int val;
void setup()
{
beginNet("localhost", 5204);
}
void loop()
{
// Sets the background color to the value received from the server
background(val);
}
// Called every time there is data available to read
void netEvent()
{
// Gets the value from the server
val = Integer.parseInt(net);
}
|
|
|
Description |
|
The Processing network library makes it easy to read and write data to and from other computers on the Net. The first step is to decide if you want to create a server or a client. A server broadcasts incoming data from clients or any data to all the connected clients. A client reads and writes data to another application or computer connected to the network. To start a server, write beginNet(port), with port specifying the location the server will be listening for clients to connect. This creates a server on your computer. To start a client, call beginNet(host, port), with host specifying which computer and port which location to connect to. Use a port number greater than 1024, since the first 1024 ports are reserved for predefined network services. You may use numbers up to 65535. You can run both the client and server applications in the same computer at the same time, but only one server in a specified port. Multiple client instances can connect to the same server in the same port at the same time. To connect to a server running in the local computer use "localhost" as the host, otherwise specify an IP address or a valid hostname like "www.proce55ing.net". The beginNet() function must be placed in setup(). For now, the network functions are only available for applications and will not run within a web browser. |
 |
|
|
Syntax |
|
beginNet(port)
beginNet(host, port)
|
 |
|
|
Parameters |
|
host |
|
String: name of the server to connect to
|
port |
|
int: port number to connect to
|
|
 |
|
|
Returns |
|
None |
 |
|
|
Usage |
|
Application |
 |
|
|
Related |
|
endNet() netWrite() netEvent() net |
|