You can use the Instrument Control Toolbox.
Until a relatively recent version (R2011b I think it was), ICT was not able to act as a TCP server (but client was okay), but that limitation is no longer present.
There is a MATLAB File Exchange contribution "tcpudpip" which can be used as a replacement for the ICT networking capabilities.
Note: if you are wanting to create "raw sockets" (e.g., for custom headers, or for IP protocols other than UDP or TCP) or if you are wanting to go in to packet snooping mode, then the above-mentioned tools are not designed for that work, partly because raw sockets require privileged device access.