spanishsteps
Programmer
Hello everybody,
I've a program where I can start matlab on a server where the ip-address and port no's are the inputs.As of now,these inputs are hard-coded in the code.When the IP-address matched with that of my local machine, then this works fine.I'm kinda confused in order to modify this code to make it working on a different machine.Could somebody pls help me.
Thanks for your time.
Heres the code under the action event
and the class file looks like
I've a program where I can start matlab on a server where the ip-address and port no's are the inputs.As of now,these inputs are hard-coded in the code.When the IP-address matched with that of my local machine, then this works fine.I'm kinda confused in order to modify this code to make it working on a different machine.Could somebody pls help me.
Thanks for your time.
Heres the code under the action event
Code:
if (event.getActionCommand().equals(StartRC)){
MatlabRCSocket = new Socket("131.246.110.43",7777);
in = new DataInputStream(MatlabRCSocket.getInputStream());
out = new DataOutputStream(MatlabRCSocket.getOutputStream());
System.out.println(in.readUTF());
remote = true;
command.setText("");
startRC.setEnabled(false);
stopRC.setEnabled(true);
return;
}
if (event.getActionCommand().equals(StopRC)){
in.close();
out.close();
MatlabRCSocket.close();
System.out.println("Connection ended");
remote = false;
startRC.setEnabled(true);
stopRC.setEnabled(false);
return;
}
Code:
class MatlabRCServer
extends Thread
{
private MatEng engine;
DataInputStream in;
DataOutputStream out;
Socket MatlabRCSocket;
ServerSocket MatlabRCServerSocket;
public MatlabRCServer()
{
try {
MatlabRCServerSocket = new ServerSocket(7777);
} catch (IOException e) {
System.out.println("ServerSocket-Error" + e.getMessage());
}
}
public void run ()
{
while (true) {
try {
MatlabRCSocket = MatlabRCServerSocket.accept();
in = new DataInputStream(MatlabRCSocket.getInputStream());
out = new DataOutputStream(MatlabRCSocket.getOutputStream());
engine = new MatEng();
engine.setOutputBuffer(4096);
out.writeUTF("Matlab Engine started");
out.flush();
while (true) {
engine.evalString(in.readUTF());
out.writeUTF(engine.getOutput());
out.flush();
}
} catch (IOException e1) {
} finally {
System.out.println("Server: Connection ended");
engine.close();
try{
in.close();
out.close();
MatlabRCSocket.close();
} catch (IOException e2){
System.out.println("Exception in finally in MatlabRCServer");
}
}
}
}
}