(connectionId: string, data: Buffer)
| 204 | } |
| 205 | |
| 206 | public sendToClient(connectionId: string, data: Buffer): SendResult { |
| 207 | const connection = this.connections.get(connectionId); |
| 208 | if (!connection) { |
| 209 | return { |
| 210 | success: false, |
| 211 | error: 'Connection not found', |
| 212 | connectionId |
| 213 | }; |
| 214 | } |
| 215 | |
| 216 | if (connection.clientSocket.destroyed || !connection.clientSocket.writable) { |
| 217 | return { |
| 218 | success: false, |
| 219 | error: 'Client socket is not writable', |
| 220 | connectionId |
| 221 | }; |
| 222 | } |
| 223 | |
| 224 | try { |
| 225 | connection.clientSocket.write(data); |
| 226 | |
| 227 | this.log(`Sent ${data.length} bytes to client ${connectionId}`); |
| 228 | this.emit('data', connectionId, 'server->client', data); |
| 229 | |
| 230 | return { |
| 231 | success: true, |
| 232 | connectionId |
| 233 | }; |
| 234 | } catch (error) { |
| 235 | const errorMessage = error instanceof Error ? error.message : 'Unknown error'; |
| 236 | this.log(`Failed to send data to client ${connectionId}: ${errorMessage}`); |
| 237 | return { |
| 238 | success: false, |
| 239 | error: errorMessage, |
| 240 | connectionId |
| 241 | }; |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | public sendToAllClients(data: Buffer): readonly SendResult[] { |
| 246 | const connectionIds = Array.from(this.connections.keys()); |
no test coverage detected