本文整理匯總了TypeScript中dgram.Socket類的典型用法代碼示例。如果您正苦於以下問題:TypeScript Socket類的具體用法?TypeScript Socket怎麽用?TypeScript Socket使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Socket類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: Buffer
ds.bind();
ds.bind(41234);
ds.bind(4123, 'localhost');
ds.bind(4123, 'localhost', () => { });
ds.bind(4123, () => { });
ds.bind(() => { });
const addr: net.AddressInfo | string = ds.address();
ds.send(new Buffer("hello"), 0, 5, 5000, "127.0.0.1", (error: Error | null, bytes: number): void => {
});
ds.send(new Buffer("hello"), 5000, "127.0.0.1");
ds.setMulticastInterface("127.0.0.1");
ds = dgram.createSocket({ type: "udp4", reuseAddr: true, recvBufferSize: 1000, sendBufferSize: 1000, lookup: dns.lookup });
}
{
let _socket = new dgram.Socket();
let _boolean: boolean;
const _err: Error = new Error();
const _str = '';
const _rinfo: net.AddressInfo = {
address: 'asd',
family: 'asd',
port: 1,
};
/**
* events.EventEmitter
* 1. close
* 2. error
* 3. listening
* 4. message
*/
示例2: Promise
return new Promise((resolve, reject) => {
try {
if (arg4 !== undefined) {
this.socket.send(arg1, arg2, arg3, arg4, arg5, (err, sent) => {
if (err) {
reject(err)
} else {
resolve(sent)
}
})
} else {
this.socket.send(arg1, arg2, arg3, (err, sent) => {
if (err) {
reject(err)
} else {
resolve(sent)
}
})
}
} catch (err) {
reject(err)
}
})
示例3: setMulticastInterface
setMulticastInterface (multicastInterface: string): void {
this.socket.setMulticastInterface(multicastInterface)
}
示例4: setMulticastTTL
setMulticastTTL (ttl: number): void {
this.socket.setMulticastTTL(ttl)
}
示例5: setTTL
setTTL (ttl: number): void {
return this.socket.setTTL(ttl)
}
示例6: setBroadcast
setBroadcast (flag: boolean): void {
this.socket.setBroadcast(flag)
}
示例7: address
address (): AddressInfo {
return this.socket.address() as AddressInfo
}
示例8: addMembership
addMembership (multicastAddress: string, multicastInterface?: string): void {
return this.socket.addMembership(multicastAddress, multicastInterface)
}
示例9: getRecvBufferSize
getRecvBufferSize (): number {
return this.socket.getRecvBufferSize()
}
示例10: resolve
this.socket.bind(arg1, () => {
const address = this.socket.address() as AddressInfo
resolve(address)
})