This page last changed on Nov 13, 2011 by marcel.schot.

We use the mochad software to the X10 switches and had the problem that after one or two button presses on the panel an error message telling us that the server does not responds appears. It turned out that the socket command waits for a reply on the socket of at least 200 characters, comething that does not always happen or might arrive a bit late.

After downloading the sources I saw that the message received from the socket is never given back to the client so it might be removed or my alteration can be used to wait for a limited time for the data to arrive before continuing. We have implemented this in out setup and it works great now.

Altered readReply method for controller.protocol.socket.TCPSocketCommand

/**
* @param socket
* @return the response read from the socket.
* @throws IOException
*/
private String readReply(java.net.Socket socket) throws IOException {
boolean stopReading = false;
long lastRead = 1;
long strRead = 0;
String reply = "";
// Get socket channel and configure non blocking
// to be able to read just as much as has been delivered
// on the socket
SocketChannel sc = socket.getChannel();
sc.configureBlocking(false);
while(!stopReading){
ByteBuffer bb = ByteBuffer.allocate(200);
// The read function on the channel will deliver at most
// 200 (the buffer length) bytes and at least 0 if none are
// available yet.
strRead = sc.read(bb);
if(strRead == 0 && lastRead == 0 ){
stopReading=true;
}else{
// This might go wrong on unicode replies! A single byte
// is read while a second one is underway....
// Because the reply is not returned to the client no
// fix is created.
reply = reply.concat(new String(bb.array()));
lastRead = strRead;
}
try{
// sleep at most 2 times this number of miliseconds before
// stopping to wait for a reaction.
Thread.sleep(50);
}catch(Exception ex){}
}
return reply;
}

I tried to close OR sockets from the mochad side. Someone pointed out sending ok\r from mochad will cause OR to close the socket. I pushed a fix but it is not in the 0.1.13 release. I think it needs more testing so please try building from master. mochad with this fix works with the following and the Android client installed from the Android Market.
OpenRemote-Controller-2.0.0_SNAPSHOT_20110611.zip

git://mochad.git.sourceforge.net/gitroot/mochad/mochad

Thanks,
mmauka

Posted by mmauka at Dec 29, 2011 08:17
Document generated by Confluence on Jun 05, 2016 09:32