本文整理汇总了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)
})