3 Copyright (C) 2005-2007 Martin Koegler <mkoegler@auto.tuwien.ac.at>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 In addition to the permissions in the GNU General Public License,
11 you may link the compiled version of this file into combinations
12 with other programs, and distribute those combinations without any
13 restriction coming from the use of this file. (The General Public
14 License restrictions do apply in other respects; for example, they
15 cover modification of the file, and distribution when not linked into
16 a combine executable.)
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 private int readlen = 0;
29 private byte[] head = null;
30 private byte[] data = null;
33 private InputStream is;
34 private OutputStream os;
36 public EIBConnection (String host) throws IOException
41 public EIBConnection (String host, int port) throws IOException
43 con = new Socket (host, port);
44 is = con.getInputStream ();
45 os = con.getOutputStream ();
48 protected int _EIB_SendRequest (byte[]data) throws IOException
51 throw new IOException ("connection closed");
52 byte len[] = new byte[2];
53 if (data.length > 0xffff || data.length < 2)
58 len[0] = (byte) ((data.length >> 8) & 0xff);
59 len[1] = (byte) ((data.length) & 0xff);
65 protected int _EIB_CheckRequest (boolean block) throws IOException
69 throw new IOException ("connection closed");
73 if (!block && is.available () < 1)
77 res = is.read (head, readlen, 2 - readlen);
80 throw new IOException ("connection closed");
85 res = SHORT2INT (head[0], head[1]);
88 if (!block && is.available () < 1)
90 res = is.read (data, readlen - 2, data.length + 2 - readlen);
93 throw new IOException ("connection closed");
99 protected int _EIB_GetRequest () throws IOException
103 if (_EIB_CheckRequest (true) == -1)
106 while (readlen < 2 || (readlen >= 2 && readlen < data.length + 2));
111 public int EIB_Poll_Complete () throws IOException
113 if (_EIB_CheckRequest (false) == -1)
115 if (readlen < 2 || (readlen >= 2 && readlen < data.length + 2))
120 public int EIBClose () throws IOException
123 throw new IOException ("connection closed");
137 public int EIBClose_sync () throws IOException
142 } catch (Exception e)