Code Samples
Printing is a plain TCP socket, so every language does the same three things: connect to
virtual-printer.online on your printer's port, write the bytes, close the connection. Encoding matters —
the samples below use CP437, the default code page; see
Code pages if your receipt has non-ASCII text.
using System.Net.Sockets;
using System.Text;
// Raw TCP, like printing to a network printer on 9100 - use your printer's own port.
var client = new TcpClient("virtual-printer.online", 9107);
var stream = client.GetStream();
var data = Encoding.GetEncoding(437).GetBytes("Hello from Virtual Printer!\n");
stream.Write(data, 0, data.Length);
client.Close();
#include <winsock2.h>
#include <ws2tcpip.h>
#include <iostream>
#pragma comment(lib, "Ws2_32.lib")
int main() {
WSADATA wsaData;
WSAStartup(MAKEWORD(2, 2), &wsaData);
SOCKET sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_port = htons(9107); // your printer's port from the 9100 block
inet_pton(AF_INET, "virtual-printer.online", &addr.sin_addr);
connect(sock, (sockaddr*)&addr, sizeof(addr));
const char* data = "Hello from Virtual Printer!\n";
send(sock, data, strlen(data), 0);
closesocket(sock);
WSACleanup();
return 0;
}
const net = require('net');
// Raw TCP, like printing to a network printer on 9100 - use your printer's own port.
const client = net.connect({ host: 'virtual-printer.online', port: 9107 }, () => {
const buffer = Buffer.from('Hello from Virtual Printer!\n', 'latin1');
client.write(buffer);
client.end();
});
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Raw TCP, like printing to a network printer on 9100 - use your printer's own port.
sock.connect(('virtual-printer.online', 9107))
data = 'Hello from Virtual Printer!\n'.encode('cp437')
sock.sendall(data)
sock.close()