3 import java
.io
.BufferedReader
;
4 import java
.io
.IOException
;
5 import java
.io
.InputStreamReader
;
6 import java
.io
.PrintWriter
;
7 import java
.net
.InetAddress
;
8 import java
.net
.Socket
;
9 import java
.net
.UnknownHostException
;
11 import de
.learnlib
.api
.SUL
;
12 import de
.learnlib
.api
.SULException
;
15 * Socket interface to connect to an SUT/test adapter over TCP.
17 * As an example, type into a unix terminal "nc -vl {ip} {port}" (where {ip} and
18 * {port} are the chosen values), and run this socketSUL. You can now control the
19 * SUL through the terminal.
20 * @author Ramon Janssen
22 public class SocketSUL
implements SUL
<String
, String
>, AutoCloseable
{
23 private final BufferedReader SULoutput
;
24 private final PrintWriter SULinput
;
25 private final Socket socket
;
26 private final boolean extraNewLine
;
27 private final String resetCmd
;
30 * Socket-interface for SUTs. Connects to a SUT (or test-adapter)
31 * @param ip the ip-address
32 * @param port the tcp-port
33 * @param extraNewLine whether to print a newline after every input to the SUT
34 * @param resetCmd the command to send for resetting the SUT
35 * @throws UnknownHostException
38 public SocketSUL(InetAddress ip
, int port
, boolean extraNewLine
, String resetCmd
) throws UnknownHostException
, IOException
{
39 this.socket
= new Socket(ip
, port
);
40 this.SULoutput
= new BufferedReader(new InputStreamReader(socket
.getInputStream()));
41 this.SULinput
= new PrintWriter(socket
.getOutputStream(), true);
42 this.extraNewLine
= extraNewLine
;
43 this.resetCmd
= resetCmd
;
49 this.SULinput
.write(this.resetCmd
+ System
.lineSeparator());
51 this.SULinput
.write(this.resetCmd
);
53 this.SULinput
.flush();
62 public String
step(String input
) throws SULException
{
64 this.SULinput
.write(input
+ System
.lineSeparator());
66 this.SULinput
.write(input
);
68 this.SULinput
.flush();
70 return this.SULoutput
.readLine();
71 } catch (IOException e
) {
72 throw new SULException(e
);
77 public void close() throws Exception
{