This is my code:
import controlP5.*; import oscP5.*; import netP5.*;
/********************************************************************************/ ControlP5 cp5; controlP5.Button BCONECTAR, BDESCONECTAR; /********************************************************************************/
/********************************************************************************/ OscP5 oscP5tcpClient; NetAddress myServerAddress; /********************************************************************************/
PFont myFont;
/********************************************************************************/ int myColor = color(255), c1, c2; float n,n1; boolean INICIO=true; /********************************************************************************/
/********************************************************************************/ void setup() { size(540,960); noStroke();
myFont = createFont("Georgia", 32);
cp5 = new ControlP5(this); /********************************************************************************/ BCONECTAR = cp5.addButton("CONECTAR") .setValue(0) .setPosition(100,100) .setSize(180,75) ;
BCONECTAR.captionLabel() .setSize(50) .setFont(myFont) .toUpperCase(false) .setText("CONECTAR") ;
BCONECTAR.getCaptionLabel().align(ControlP5.CENTER, ControlP5.CENTER);
/********************************************************************************/
BDESCONECTAR = cp5.addButton("DESCONECTAR") .setValue(1) .setPosition(100,195) .setSize(240,75) ;
BDESCONECTAR.captionLabel() .setSize(50) .setFont(myFont) .toUpperCase(false) .setText("DESCONECTAR") ;
BDESCONECTAR.getCaptionLabel().align(ControlP5.CENTER, ControlP5.CENTER);
/********************************************************************************/
}
/********************************************************************************/
/********************************************************************************/ void draw() { background(myColor); myColor = lerpColor(c1,c2,n); n += (1-n)* 0.1; } /********************************************************************************/
/********************************************************************************/
public void CONECTAR(int theValue) {
println("CONECTAR: " + theValue);
c1 = c2;
c2 = color(0,160,100);
if(INICIO==false)
{
oscP5tcpClient = new OscP5(this, "192.168.1.97", 5000, OscP5.TCP);
myServerAddress = new NetAddress("192.168.1.97", 5000);
}
}
public void DESCONECTAR(int theValue) {
println("DESCONECTAR: " + theValue);
c1 = c2;
c2 = color(150,0,0);
if(INICIO==false)
{
oscP5tcpClient.stop();
oscP5tcpClient.dispose();
oscP5tcpClient.disconnect(myServerAddress);
}
INICIO=false;
}
/********************************************************************************/
When I push the button DESCONECTAR the server still says Connected.
Could you please show me the right way to close TCP client?