// The lines FILIUS' programs write into their windows, as Java's German // message bundle says them: for comparing the core's structured lines with // what the Java oracle recorded (echoJava.test.ts, webJava.test.ts). import type { EchoServerLogEntry, SendFailure, SimpleClientLogEntry } from '../src/index.js'; /** Java's client and server look every 100 ms whether they are connected, or switched off; the core at once. */ export const POLL_MILLISECONDS = 100; /** Lines Java writes after one of its 100 ms looks. */ const POLLED = new Set(['Verbindung hergestellt', 'Server-Socket geschlossen']); export const isPolled = (text: string) => POLLED.has(text) || /^Verbindung zu .* hergestellt$/.test(text); /** sw_tcpsocket_msg6, msg7, msg8. */ export const SEND_FAILURES: Record = { notConnected: 'Verbindung nicht aufgebaut!', connectionLost: 'Verbindung wurde unterbrochen', timedOut: 'Zeitüberschreitung während des Versands einer Nachricht', }; /** A server's line as Java's window shows it (German message bundle). */ export function serverText(entry: EchoServerLogEntry): string { switch (entry.kind) { case 'acceptingStarted': return 'Annahme von Verbindungsanfragen gestartet'; case 'acceptingStopped': return 'Annahme von Verbindungsanfragen beendet'; case 'serverSocketClosed': return 'Server-Socket geschlossen'; case 'serverSocketFailed': return 'Server-Socket konnte nicht geöffnet werden.'; case 'connectionAccepted': return `Verbindung zu ${entry.address}:${entry.port} hergestellt`; case 'received': return `>>${entry.text}`; case 'sent': return `<<${entry.text}`; case 'sendFailed': return SEND_FAILURES[entry.failure]; case 'connectionClosed': return `Socket zu ${entry.address}:${entry.port} geschlossen`; } } export const CONNECT_FAILURES = { unresolved: 'Ziel konnte nicht bestimmt werden!', timedOut: 'Zeitüberschreitung beim Verbindungsaufbau', failed: 'Aktives Öffnen des Sockets fehlgeschlagen', }; /** A client's line as Java's window shows it. */ export function clientText(entry: SimpleClientLogEntry): string { switch (entry.kind) { case 'connected': return 'Verbindung hergestellt'; case 'connectFailed': return `Fehler beim Verbindungsaufbau\n${CONNECT_FAILURES[entry.failure]}`; case 'disconnected': return 'Verbindung getrennt'; case 'notConnected': return 'Fehler beim Verbindungsaufbau'; case 'sent': return `<<${entry.text}`; case 'received': return `>>${entry.text}`; case 'sendFailed': return SEND_FAILURES[entry.failure]; case 'connectionClosed': return `Socket zu ${entry.address}:${entry.port} getrennt`; case 'receiveFailed': return 'Keine Verbindung hergestellt!'; } }