I'm trying to create a scenario on my Macbook with Mojave in Anylogic, which is part of agent-based simulation with many different tools. My idea is to connect Anylogic via Java Interface to Eclipse. The main problem is, that Anylogic somehow does not respond.
I have tried many different codes with sockets, but could not find one, which worked for Anylogic. I'm using the free version of Anylogic and created a Java Interface under my Main Project. To run the Java Interface I press right-click on the file and select 'run with Java Editor'
In comparison to that I create two files in Eclipse, with one being the Server and one the Client and it worked.
so this is my Eclipse, which I guess should be fine https://www.minpic.de/i/7wbk/nv00b
this is my main model in Anylogic https://www.minpic.de/i/7wbn/pzuut
and there is the Java interface with the server code in it. https://www.minpic.de/i/7wbo/1mxsl4
Im pretty new to coding so hopefully you guys can help me.
public class server{
public static void main(String[] args) throws IOException {
ServerSocket ss = new ServerSocket(4995);
Socket s = ss.accept();
System.out.println("Client connected");
DataInputStream dout = new DataInputStream(s.getInputStream());
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
while(true) {
String yoo = dout.readUTF();
System.out.println("client" + yoo);
if(yoo.equalsIgnoreCase("exit"));
break;
}
ss.close();
}
}
public class client{
public static void main(String[] args) throws IOException {
Socket s = new Socket("localhost",4995);
DataOutputStream dout = new DataOutputStream(s.getOutputStream());
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
while (true)
{
String so= br.readLine();
dout.writeUTF(so);
System.out.println("client" + so);
if(so.equalsIgnoreCase("exit"));
break;
}
s.close();
}
}
I was expecting the consoles of both programs to show me messages I have send via the console, but neither of the programs show me the messages of what I wrote in the other program.