How to send eof signal, over a socket, to a command running in remote shell?

I've programmed in Python, using sockets, a remote shell application, where I send commands to be executed on another PC.
Everything works fine (for most commands), except a command like cat > file is causing me problems.
Normally, I would terminate the command above with CTRL + D (eof signal), but pressing CTRL + D in my client, doesn't send the signal to the remote shell. Therefore I have no means of terminating the command and I'm stuck.
Anyone have suggestions ?
eof is not a signal but is implemented by the tty driver as a read of length 0 when you type ctrl-d.
If your remote is not running in a tty then you cannot generate an eof as you cannot send a packet that reads as of length 0. However if you run a program like script /dev/null as the first command in your remote shell, then this will envelop your shell inside a pseudo-tty, and you will be able to send a real ctrl-d character (hex 0x04) and the pty will convert this to eof and end a cat, for example. Send a stty -a to the remote to check that eol is enabled in your pty.

stty -a on my terminal says lnext = ^V (literal-next char) so I can type ctrl-vctrl-d to input a real hex 0x04 char.
I chose script as I know it effectively interposes a pseudo-tty in the communication, and does nothing to the data stream. This is not its original purpose (see its man page), but that doesn't matter.
How to send `eof` signal, over a socket, to a command running in remote shell?