EasyManua.ls Logo

Evolution Robotics ER1 - Page 110

Default Icon
170 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Chapter 10 Application Programmer’s Interface
10-24 ER1 User Guide
if (_socket != null) { disconnect(); }
_address = "";
_port = 0;
try {
// Create a new socket connection.
_socket = new Socket(address, port);
try {
// Set the output stream.
_write_stream = new DataOutputStream(_socket.getOutputStream());
_read_stream = new BufferedInputStream(_socket.getInputStream());
}
catch (Exception ex) {
System.out.println(ex.toString());
}
_address = address;
_port = port;
return true;
}
catch (Exception ex) {
System.out.println(ex.toString());
//throw ex;
return false;
}
}
public String readString()
{
try
{
if (_read_stream == null) {
System.out.println("Error: _read_stream is null.");
return null;
}
try {
int size;
String msg;
do {
size = _read_stream.available();
if (size != 0) {
byte[] buffer = new byte[size];
_read_stream.read(buffer, 0, size);
msg = new String(buffer);
return msg;
}
Thread.sleep(50);
} while (size == 0);
}
catch (Exception ex) {
System.out.println(ex.toString());
return null;
}
}
catch (RuntimeException ex)
{
System.out.println(ex.toString());
return null;
//Global.applet.showDebug(ex.toString());
}
return null;
}
public boolean sendString(String s) {

Table of Contents