# MX\_FILESOCK

> [HTML Version](mx_filesock.htm)

_Added October 2016_

**xcall MIAMEX, MX\_FILESOCK, ch, socket, status**

MX\_FILESOCK (MIAMEX 187) binds a TCP socket to a sequential file channel so that PRINT #CH and/or INPUT #CH transfers data over the socket rather than to/from the file. 

**Parameters**

_ch_  ([Num](num.md))  \[in\] 

must be a file channel (> 0) open for sequential input or output. Typically you would open the file using the .NULL filespec as described in [.NULL Files](nullfiles.md).

_socket_  ([Num](num.md))  \[in\]

must be a valid socket opened via TCPX[xs](keyword-types.md).

_status_  (Signed [Num](num.md)) \[out\]

returns 0 for success, else error.

If _ch_ was open for output, then after the successful completion of the MX\_FILESOCK call, PRINT #CH statements will output to the socket instead of the file. Similarly, if _ch_ was open for input, then INPUT #_ch_ statements will read from the socket.

Note that while sockets are bidirectional, sequential file channels are not, so if you want to both input and output to the socket this way, you will need to open two file channels and bind them both to the same socket with two separate MX\_FILESOCK calls.

Once the file channel is bound to the socket, closing the file channel will also close the socket.

To simplify the operation of opening the file and socket and binding the two together, a pair of functions has been added to the SOSFUNC: library:

Fn'FileSock'Out(ch, socket, server\$)

Fn'FileSock'In(ch, socket, server\$)



See [fnfilesock.bsi in SOSLIB:\[907,10\]](https://bitbucket.org/microsabio/soslib/src/master/907010/fnfilesock.bsi) for details.

**History**

2016 September, A-Shell 6.3.1524:  Routine added to A-Shell