A small java class that implements a channel multiplexor in a separate thread and allows you to register socket connections and Matlab callback functions for socket channel events (OP_READ and OP_ACCEPT). Leaves the command prompt available for you to keep working while it runs in the background firing Matlab callbacks to process the data. The SocketChannel that causes the event is passed into the Matlab callback in the event data. There is no need to open multiple instances of Matlab to test it. I have included an echo server for testing.
I get data rates >100Mbps.
For a complete example see "main.m" and "demoServer.m" in the attached files.
You will need to edit your "classpath.txt" (type 'edit classpath.txt' at the matlab command prompt) and add the path to the bin directory that contains the java classes from the zip file.
It should look something like this when you are done:
You then MUST restart Matlab.
The class files were built on my Windows 32 bit machine against Java 1.5.0_07.
I have included the source code so that you can compile the code yourself on your own system if you desire. I suppose that this is necessary if you are running 64 bit.
This submission was inspired by my job and enabled by the useful information on UndocumentedMatlab.com. Particularly this post:
There is still a lot of work to be done to make it more configurable and implement all of the network options but what is there seems to run well.
Try it out and let me know what additional features would be helpful.... and leave me a comment to let me know what you think.
Jude Collins (2023). matSock (https://www.mathworks.com/matlabcentral/fileexchange/35608-matsock), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform CompatibilityWindows macOS Linux
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!
Added in the serverBind() m-file that was left out last time I uploaded it. Made a few other tweaks.
Included the java source code so that you can build the class yourself.
Implemented the OP_ACCEPT callback for server sockets.