File Exchange

image thumbnail

TCP Output Socket

version 1.0 (5.4 KB) by

MATLAB TCP Output Socket using a Java helper class for threaded client connection management



View License

An output socket that allows zero or more TCP client connections to be made.

A separate thread manages the client connections allowing for multiple clients to connect and disconnect at any time.

Not just for data communication but also useful as a debug output monitoring tool.


output_port = 1234;
output_socket = MatlabOutputSocket(output_port);

% Write a string out
output_socket.write(int8(sprintf('Hi there how are you?\r\n')));

% Write some raw data out
output_socket.write(rand(4, 'single'));

% close socket connection

For more details and an explanation of the Java helper class see:

Comments and Ratings (5)

Rodney Thomson

Rodney Thomson (view profile)

Oh I see what you mean now.

In that part of the example we are directly constructing the JAVA OBJECT (OutputSocket) and using that. The strange text (OutputSocket@1c68b29) is likely to be how Java objects are represented in MATLAB.

Likely it is saying <class/type>@<memory location>


Thuong (view profile)

Thank you, Rodney!
It works well now.

But what i meant is in your example, it shows that output_socket is:
>> output_socket = OutputSocket(1234)
output_socket =
So, I dont understand what "OutputSocket@1c68b20" really means? Could you happen to explain about this.

Rodney Thomson

Rodney Thomson (view profile)

Thuong, that is entirely to be expected. You did not place a semi-colon (;) at the end of your statement so MATLAB plotted the result of the assignment to output_socket.

That is, it created a MatlabOutputSocket with no properties. You can click on 'Methods' in the command window to show the list of methods you can use (for this example it is just close() and write()!)


Thuong (view profile)

Hi Rodney,
Thank you for your helpful codes
I put all files in current working folder, and run two commands
>> javaaddpath(pwd)
>> output_socket=MatlabOutputSocket(1234)
But the result is
output_socket =

MatlabOutputSocket handle with no properties.
Methods, Events, Superclasses

I dont know why, would you help me with that
Thank you!


zhang (view profile)

MATLAB Release
MATLAB 7.8 (R2009a)
Tags Add Tags

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today