Hi. I ran into a simple problem I dont understand just
how to check if socket is connected
how to check if input data is available for read
For example in C# class Socket have a property “.IsConnected” and socket’s stream have a property “.DataAvailable” or “.Length”. But I can’t find something like that in Haxe
Mybe somebody knowns a simply solution for these (‘standard’, as it seems to me) features?
Thanks.
Probably, there is no simply and beauty solution Only play with exceptions, for example:
class Client {
static function main() {
var s = new sys.net.Socket();
s.setBlocking(false);
s.connect(new sys.net.Host("localhost"), 5000);
trace("client connected...");
while (s != null) {
try
{
var r = s.input.readByte();
trace('r is $r');
}
catch (e:Dynamic) {
trace(e); // Blocked - no data, Eof - connection was terminated
}
Sys.sleep(1);
}
}
}