using socket.io with events from matlab to a java sever

15 ビュー (過去 30 日間)
Marwan Tabet
Marwan Tabet 2017 年 6 月 15 日
回答済み: Nagarjuna Manchineni 2017 年 6 月 20 日
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,

回答 (1 件)

Nagarjuna Manchineni
Nagarjuna Manchineni 2017 年 6 月 20 日
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!

カテゴリ

Help Center および File ExchangeJava Client Programming についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by