using socket.io with events from matlab to a java sever
15 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello, I am trying to connect from Matlab to a server that uses socket connection and publishes JSON files through event. This data can be accessed via the socket.on method in java or @sio.on('event' ) in python. Can someone indicate how this can be achieved with Matlab?
I was able to connect to the server with the following:
import java.net.Socket
import java.io.*
import socket.io.*
input_socket = Socket(host, port);
But I am unable to listen to the event on the socket to get the data.
Thanks,
0 comentarios
Respuestas (1)
Nagarjuna Manchineni
el 20 de Jun. de 2017
I see that you are trying to connect the socket by using the following syntax:
input_socket = Socket(host, port);
This is causing the issue. For creating a Java object inside MATLAB you need to use the function 'javaObject'.
See the following documentation link for more information:
For example, for creating a socket you can use the following command:
client = javaObject('java.net.Socket', 'localhost', 4000);
For sending data from the client to server:
outToServer = client.getOutputStream();
out = javaObject('java.io.DataOutputStream', outToServer)
out.writeUTF('Hello from client');
For reading the data from the server:
inFromServer = client.getInputStream();
in = javaObject('java.io.DataInputStream', inFromServer)
in.readUTF()
I hope this helps!
0 comentarios
Ver también
Categorías
Más información sobre Java Client Programming en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!