forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson-socket.d.ts
71 lines (59 loc) · 3.14 KB
/
json-socket.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Type definitions for json-socket v0.1.2
// Project: https://github.com/sebastianseilund/node-json-socket
// Definitions by: Sven Reglitzki <https://github.com/svi3c/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../node/node.d.ts"/>
declare module "json-socket" {
import {Socket} from "net";
class JsonSocket extends Socket {
constructor(socket: Socket);
/**
* sends a single message and closes the connection instantly. Use this if you need to send a server a message,
* but you don't need any response.
* @param port port to send the message to
* @param host host to send the message to
* @param message the message to send
* @param callback will be called after the message has been sent
*/
static sendSingleMessage(port: number, host: string, message: any, callback: (err: Error) => void): void;
/**
* sends a single message, waits for a single response message from the server and closes the connection right after.
* Use this if you need to send a server a message, and get a response, but you don't need the connection to stay
* open.
* @param port port to send the message to
* @param host host to send the message to
* @param message the message to send
* @param callback will be called when the response message has been received
*/
static sendSingleMessageAndReceive(port: number, host: string, message: any, callback: (err: Error, message: any) => void): void;
/**
* Convenience method for sending an error as a message.
* @param err an Error object that should be formatted as a message
* @param callback will be called after the message has been sent
*/
sendError(err: Error, callback: (err: Error) => void): void;
/**
* Same as {@link JsonSocket.sendError}, except that the socket is closed right after the message has been sent
* using <a href="https://nodejs.org/api/net.html#net_socket_end_data_encoding">net.end()</a>.
* No more messages can be sent from either the server or client through this socket.
* @param err
* @param callback
*/
sendEndError(err: Error, callback: (err: Error) => void): void;
/**
* Sends a JSON message over the socket.
* @param message the message to send
* @param callback will be called after the message has been sent
*/
sendMessage(message: any, callback: (err: Error) => void): void;
/**
* Same as {@link JsonSocket.sendMessage}, except that the socket is closed right after the message has been sent
* using <a href="https://nodejs.org/api/net.html#net_socket_end_data_encoding">net.end()</a>.
* No more messages can be sent from either the server or client through this socket.
* @param message the message to send
* @param callback will be called after the message has been sent
*/
sendEndMessage(message: any, callback: (err: Error) => void): void;
}
export = JsonSocket;
}