Yes, slot devices are the right way to do it, that's what Just Desserts mentioned above. But per R. Belmont's comment, MAME already has a way to do what you're asking, using the BITBANGER device and related support. You can look into how that's connected to the RS-232 null modem as an example, but in principle it allows you to transmit and receive arbitrary streams of data through sockets on the host, without having to implement your own network code (and the various operating system dependencies that entails).
To experiment, you can activate this function from the command line on any driver which implements an RS-232 port by adding arguments as follows:
-<port_name> null_modem -bitbngr socket.<address>:<port>
where <port_name> is whatever the driver calls its serial port, and <address> and <port> are the IP address and port number of the socket you want to use.
In your case, if the link isn't RS-232, you can still follow the same approach to leverage BITBANGER for yourself.