Matlab - Java communication: Reading java data stream

1 visualizzazione (ultimi 30 giorni)
I have a java based eye tracking program working together with a matlab based mini-game. Matlab receives the eye tracking data as a stream and saves it successfully to a new file. Now I want to receive the eye tracking data within matlab in real time to influence the mini game properties during the playtime. I tried a bunch of stuff but am unable to obtain the data from the data stream within my main matlab executable.
Java stream code within the main matlab executable:
import java.net.Socket
import java.io.*
input_socket = Socket('localhost', 3999);
[...]
output_stream = input_socket.getOutputStream;
d_output_stream = DataOutputStream(output_stream);
input_stream = input_socket.getInputStream;
d_input_stream = DataInputStream(input_stream);
[...]
EG_comm(d_output_stream, 'stop_sending');
[...]
EG_log(d_output_stream, 'open', FileName);
[...]
EG_log(d_output_stream, 'header', []);
[...]
EG_log(d_output_stream, 'start', []);
[...]
EG_log(d_output_stream, 'mark', []);
[...]
EG_log(d_output_stream, 'stop', []);
[...]
EG_log(d_output_stream, 'close', []);
[...]
EG_comm(d_output_stream, 'close_and_recycle');
[...]
d_input_stream.close
input_stream.close
d_output_stream.close
output_stream.close
input_socket.close
EG_comm function
function [error] = EG_comm(d_output_stream, message)
error = 0;
switch message
case 'begin_sending'
message= [0 0 5 30 35]; % begin sending gaze data to client
for i=1:length(message)
d_output_stream.write(message(i),0,1);
end
d_output_stream.flush;
case 'stop_sending'
message= [0 0 5 31 36]; % stop sending gaze data to client
for i=1:length(message)
d_output_stream.write(message(i),0,1);
end
d_output_stream.flush;
case 'close_and_recycle'
message= [0 0 5 32 37]; % close and restart server
for i=1:length(message)
d_output_stream.write(message(i),0,1);
end
d_output_stream.flush;
otherwise
error = 1;
end
EG_log function
function [error] = EG_log(d_output_stream, message, filename)
error = 0;
switch message
case 'open'
message= [0 0 0 33 length(filename) uint8(filename) 1 uint8('w')];
message(3)= length(message)+1;
message(length(message)+1) = uint8(mod(sum(message),256));
for i=1:length(message)
d_output_stream.write(message(i),0,1);
end
d_output_stream.flush;
case 'header'
message= [0 0 5 34 39]; % write header
for i=1:length(message)
d_output_stream.write(message(i),0,1);
end
d_output_stream.flush;
case 'start'
message= [0 0 5 36 41]; % start logging
for i=1:length(message)
d_output_stream.write(message(i),0,1);
end
d_output_stream.flush;
case 'stop'
message= [0 0 5 37 42]; % stop logging
for i=1:length(message)
d_output_stream.write(message(i),0,1);
end
d_output_stream.flush;
case 'mark'
message= [0 0 5 38 43]; % mark event
for i=1:length(message)
d_output_stream.write(message(i),0,1);
end
d_output_stream.flush;
case 'close'
message= [0 0 5 39 44]; % close file
for i=1:length(message)
d_output_stream.write(message(i),0,1);
end
d_output_stream.flush;
otherwise
error = 1;
end

Risposte (0)

Categorie

Scopri di più su Startup and Shutdown in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by