Code covered by the BSD License  

Highlights from
TCP/IP Socket Communications in MATLAB using Java Classes


5.0 | 5 ratings Rate this file 54 Downloads (last 30 days) File Size: 3.35 KB File ID: #25249

TCP/IP Socket Communications in MATLAB using Java Classes



A simple example TCP/IP server and client using a helper Java class

| Watch this File

File Information

Provides an example Server / Client written in MATLAB that utilises the ability to call Java to perform message communication using TCP/IP.

Similar to my previous example ( but allows for much more efficient data transmission by using a helper Java class to minimise function call overhead.

To use the example:

- Start 2 instances of MATLAB
- in the first execute the following:
  message = char(mod(1:1000, 255)+1);
  server(message, 3000, 10)
- in the second execute the following:
  javaaddpath('<path to where the .class file is located>');
  data = client('localhost', 3000)

For more details see:


Tcp/Ip Socket Communications In Matlab inspired this file.

This file inspired Tcp/Ip Communications In Matlab.

MATLAB release MATLAB 7.8 (R2009a)
Other requirements Although I have developed it in MATLAB 2009a, it should work on versions as far back as R14.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (9)
07 Nov 2014 Sergio  
02 Oct 2013 Rodney Thomson

Bi-directional coms can be done by a single socket, although you still need a 'server' and a 'client'. Someone needs to wait for a connection, and the other needs to initiate the connection.

When you get the Java Socket() object, you can get both an InputDataStream and an OutputDataStream (or even a DataStream) and then read/write with the relevant stream.

30 Sep 2013 Tiago

In order to have bi-directional communication I have to create 2 Sockets? or is there any other option (sockets are bi-directional by default)?

27 Sep 2013 Tiago

My bad!
I read 'addpath' instead of 'javaaddpath'.
Thanks for the answer

27 Sep 2013 Rodney Thomson

Don't forget to add the directory containing DataReader.class to the java path:
>> javaaddpath('<path to where the .class file is located>');

(as mentioned above and on the blog page).

26 Sep 2013 Tiago

The server manage to get a connection with the client but I'm having an error in:
data_reader = DataReader(d_input_stream);

Undefined function 'DataReader' for input arguments of type ''.

Any ideas?

09 Aug 2012 Sebastian Holmqvist

Excellent! Makes a world of difference when handling string > 1 MB. I use Kevin Bartlett's "TCP/IP Communications in Matlab" ( which can optionally utilize your java classes and it's lizard fast!

19 Jan 2012 Ueli Rutishauser  
16 Nov 2009 Kevin Bartlett  

Contact us