using socket.io with events from matlab to a java sever
13 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Nagarjuna Manchineni
il 20 Giu 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 Commenti
Vedere anche
Categorie
Scopri di più su Java Client Programming in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!