Code Monkey home page Code Monkey logo

matlab-tcpip's Introduction

TCP/IP server and client for Matlab

This package contains a TCP/IP API for Matlab as well as data serialization helpers. This package doesn't require tcpip function in the Instrument Control Toolbox for Matlab, yet provides an equivalent functionality and a simple-to-use API. This is suitable to communicate between multiple Matlab instances over the TCP/IP network.

There are two high-level functions.

TCPClient - Send a TCP request.
TCPServer - Run a TCP server process.

Build

Compile MEX files and Java helpers by the attached Makefile.

make

Example

Add a path to matlab-tcpip to use the API.

addpath('/path/to/matlab-tcpip');

Plus-1 server

Start a plus-1 server at port 3000, which adds 1 to any given request.

TCPServer(@(x)x+1, 'port', 3000);

Send a request to the server running at localhost on port 3000.

response = TCPClient('localhost', 3000, 1); % Send `1`.
disp(response); % Shows `2` from the plus-1 server.

Custom callback

Serve a custom callback function dispatch at port 5000.

TCPServer(@dispatch, 'port', 5000);

Where, dispatch is a user-defined callback that takes a single input argument of a client request and returns a single output sent back to the client.

function response = dispatch(request)
%DISPATCH Process a TCP/IP request.
...

API

TCPServer

TCPServer(callback, ...)
TCPServer(callback, 'port', 0, 'serialize', true, ...)

TCPServer starts a TCP server process and respond to a request with a given function callback. Use TCPClient to communicate with this process. The server runs indefinite. Use Ctrl-C to quit the process.

The function accepts the following options.

  • port - TCP port to use. When the port number is 0, the function picks up any available port in the system. Default 0.
  • serialize - Logical flag to automatically serialize Matlab variables in request and response. When false, a callback function takes raw bytes and must return raw bytes in the output arguments. Default true.
  • onetime - If true, terminate the server upon the first request. Default false.
  • buffer_size - Size of the internal buffer. Default 4096.
  • quiet - Logical flag to suppress display messages. Default false.

TCPClient

response = TCPClient(hostname, port, request, ...)

The function accepts the following option.

  • serialize - Logical flag to automatically serialize Matlab variables in request and response. Default true.
  • buffer_size - Size of the internal buffer. Default 4096.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.