Troubleshooting TCP/IP Server Interface
Transmission Control Protocol (TCP) is a transport protocol layered on top of the Internet Protocol (IP) and is one of the most highly used networking protocols.
Issue
If you are having trouble connecting to or communicating with your server, try these troubleshooting tips.
Possible Solutions
Supported Platforms
TCP/IP is supported on these platforms:
Linux®
macOS
Windows® 10
The TCP/IP server interface is supported on the same platforms as MATLAB®. For updates to the list of currently supported platforms, see System Requirements.
Configuration and Connection
Make sure you can create a TCP/IP server object. You create it using the
tcpserver
function, which takes a port number and an
optional IP address as inputs. If you do not specify an IP address, the server
can accept a client connection at any valid IP address. The IP address that you
specify for the server should match the IP address that the client connects
to.
t = tcpserver("172.28.200.145",4000);
Check that the IP address you specify is available on your machine. To see valid IP addresses for your machine, run the following command in MATLAB on Windows.
!ipconfig
If you specify a host name instead of host IP address, you can also verify that it is a valid host name by using
resolvehost
. If the output is empty, the specified host name is invalid.resolvehost("hostname","address")
ans = '172.28.200.145'
Make sure that you do not specify a port that is already in use. In addition, you can only create one server object for a given address and port combination.
Make sure that your network adapter is enabled and connected.
Communication
Before reading from or writing to the server object, check the
Connected
property to make sure that a client is connected to it. If a client has successfully connected, the value of this property is1
(true
).t.Connected
The
ClientAddress
andClientPort
properties also provide information about the client that is connected to the server object. The value ofClientAddress
should match the value ofServerAddress
.Make sure the correct data type, such as
int16
,uint16
, ordouble
is being used withread
andwrite
. Use the same data type as the client. If reading and writing data types other thanuint8
orint8
, make sure theByteOrder
is correct.