Assigning WebSocket and net.Socket with unique id2019 Community Moderator ElectionIgnore Typescript Errors “property does not exist on value of type”webSocketServer node.js how to differentiate clientsHow to uniquely identify a socket with Node.jsNodeJS WebSocket Handshake Silently Failing?WebSockets vs. Server-Sent events/EventSourceDifferences between socket.io and websocketsWhat are Long-Polling, Websockets, Server-Sent Events (SSE) and Comet?Which websocket library to use with Node.js?Which WebSocket library to use in Android app?How to pass an active WebSocket to a clustered thread in Node.js?Why does not sending data io.sockets.emit and socket.broadcast.emitReact WebSocket integration sockjs react-websocket socketio-clientListen to Websockets in Angular 4 app with Socket.io
What is the dot in “1.2.4."
Is going from continuous data to categorical always wrong?
Can infringement of a trademark be pursued for using a company's name in a sentence?
Co-worker team leader wants to inject the crap software product of his friends into our development. What should I say to our common boss?
Is a lawful good "antagonist" effective?
Does Linux have system calls to access all the features of the file systems it supports?
Does splitting a potentially monolithic application into several smaller ones help prevent bugs?
"One can do his homework in the library"
Good allowance savings plan?
Life insurance that covers only simultaneous/dual deaths
How does Dispel Magic work against Stoneskin?
Does the Bracer of Flying Daggers benefit from the Dueling Fighting style?
Is it illegal in Germany to take sick leave if you caused your own illness with food?
What is the definition of "Natural Selection"?
What is the difference between "shut" and "close"?
Word for a person who has no opinion about whether god exists
Making a sword in the stone, in a medieval world without magic
Can "semicircle" be used to refer to a part-circle that is not a exact half-circle?
Make a transparent 448*448 image
How is the Swiss post e-voting system supposed to work, and how was it wrong?
What is the blue range indicating on this manifold pressure gauge?
Do I need to leave some extra space available on the disk which my database log files reside, for log backup operations to successfully occur?
It's a yearly task, alright
Single word request: Harming the benefactor
Assigning WebSocket and net.Socket with unique id
2019 Community Moderator ElectionIgnore Typescript Errors “property does not exist on value of type”webSocketServer node.js how to differentiate clientsHow to uniquely identify a socket with Node.jsNodeJS WebSocket Handshake Silently Failing?WebSockets vs. Server-Sent events/EventSourceDifferences between socket.io and websocketsWhat are Long-Polling, Websockets, Server-Sent Events (SSE) and Comet?Which websocket library to use with Node.js?Which WebSocket library to use in Android app?How to pass an active WebSocket to a clustered thread in Node.js?Why does not sending data io.sockets.emit and socket.broadcast.emitReact WebSocket integration sockjs react-websocket socketio-clientListen to Websockets in Angular 4 app with Socket.io
I aspire to assign Websockets and net.Sockets with unique identifiers, so when a message is received, the client is identified by the identifier attached to the socket.
Previous research:
For Websocket:
According to this and this, the following is requires:
const app = express();
const server = http.createServer(app);
const wss = new WebSocket.Server( server );
wss.on('connection', (ws) =>
ws.id = uuid.v4(); // This is the relevant line of code
ws.on('message', (msg: string) =>
...
);
For net.Socket:
Quite the same - according to this, the following is required:
var server = net.createServer();
server.on('connection', function(conn)
conn.id = uuid.v4(); // This is the relevant line of code
conn.on('data', function(data)
...
);
);
The problem
The error "Property 'id' does not exist on type 'WebSocket' [or 'Socket' accordingly]" during compilation. This explains why.
Optional Solution #1: Cast to any
The update net.Socket code will be:
var server = net.createServer();
server.on('connection', function(conn)
(conn as any).id = uuid.v4();
conn.on('data', function(data)
console.log('Session id:' + (conn as any).id);
);
);
The problem: It doesn't seem like good practice to me. I don't have references for why except for a hunch for now.
Optional Solution #2: Use a local variable [seems like a better option]
The update net.Socket code will be:
var server = net.createServer();
server.on('connection', function(conn)
const id: string = uuid.v4();
conn.on('data', function(data)
console.log('Session id:' + id);
);
);
After some experiencing, it seems to work properly.
So - the questions:
In optional solution #2: is it guaranteed that the id variable will always be available in this scope? In other words: is this solution valid? for both net.Socket & Websocket? Or is there something that I'm missing?
In general: Is there additional identifiers (perhaps built in identifiers in WebSocket and net.Socket) that can be used instead?
[Typescript version: 3.2.4].
node.js typescript sockets websocket
add a comment |
I aspire to assign Websockets and net.Sockets with unique identifiers, so when a message is received, the client is identified by the identifier attached to the socket.
Previous research:
For Websocket:
According to this and this, the following is requires:
const app = express();
const server = http.createServer(app);
const wss = new WebSocket.Server( server );
wss.on('connection', (ws) =>
ws.id = uuid.v4(); // This is the relevant line of code
ws.on('message', (msg: string) =>
...
);
For net.Socket:
Quite the same - according to this, the following is required:
var server = net.createServer();
server.on('connection', function(conn)
conn.id = uuid.v4(); // This is the relevant line of code
conn.on('data', function(data)
...
);
);
The problem
The error "Property 'id' does not exist on type 'WebSocket' [or 'Socket' accordingly]" during compilation. This explains why.
Optional Solution #1: Cast to any
The update net.Socket code will be:
var server = net.createServer();
server.on('connection', function(conn)
(conn as any).id = uuid.v4();
conn.on('data', function(data)
console.log('Session id:' + (conn as any).id);
);
);
The problem: It doesn't seem like good practice to me. I don't have references for why except for a hunch for now.
Optional Solution #2: Use a local variable [seems like a better option]
The update net.Socket code will be:
var server = net.createServer();
server.on('connection', function(conn)
const id: string = uuid.v4();
conn.on('data', function(data)
console.log('Session id:' + id);
);
);
After some experiencing, it seems to work properly.
So - the questions:
In optional solution #2: is it guaranteed that the id variable will always be available in this scope? In other words: is this solution valid? for both net.Socket & Websocket? Or is there something that I'm missing?
In general: Is there additional identifiers (perhaps built in identifiers in WebSocket and net.Socket) that can be used instead?
[Typescript version: 3.2.4].
node.js typescript sockets websocket
1
for 1, it's valid solution, check this developer.mozilla.org/en-US/docs/Web/JavaScript/Closures
– Tubc
Mar 9 at 10:56
add a comment |
I aspire to assign Websockets and net.Sockets with unique identifiers, so when a message is received, the client is identified by the identifier attached to the socket.
Previous research:
For Websocket:
According to this and this, the following is requires:
const app = express();
const server = http.createServer(app);
const wss = new WebSocket.Server( server );
wss.on('connection', (ws) =>
ws.id = uuid.v4(); // This is the relevant line of code
ws.on('message', (msg: string) =>
...
);
For net.Socket:
Quite the same - according to this, the following is required:
var server = net.createServer();
server.on('connection', function(conn)
conn.id = uuid.v4(); // This is the relevant line of code
conn.on('data', function(data)
...
);
);
The problem
The error "Property 'id' does not exist on type 'WebSocket' [or 'Socket' accordingly]" during compilation. This explains why.
Optional Solution #1: Cast to any
The update net.Socket code will be:
var server = net.createServer();
server.on('connection', function(conn)
(conn as any).id = uuid.v4();
conn.on('data', function(data)
console.log('Session id:' + (conn as any).id);
);
);
The problem: It doesn't seem like good practice to me. I don't have references for why except for a hunch for now.
Optional Solution #2: Use a local variable [seems like a better option]
The update net.Socket code will be:
var server = net.createServer();
server.on('connection', function(conn)
const id: string = uuid.v4();
conn.on('data', function(data)
console.log('Session id:' + id);
);
);
After some experiencing, it seems to work properly.
So - the questions:
In optional solution #2: is it guaranteed that the id variable will always be available in this scope? In other words: is this solution valid? for both net.Socket & Websocket? Or is there something that I'm missing?
In general: Is there additional identifiers (perhaps built in identifiers in WebSocket and net.Socket) that can be used instead?
[Typescript version: 3.2.4].
node.js typescript sockets websocket
I aspire to assign Websockets and net.Sockets with unique identifiers, so when a message is received, the client is identified by the identifier attached to the socket.
Previous research:
For Websocket:
According to this and this, the following is requires:
const app = express();
const server = http.createServer(app);
const wss = new WebSocket.Server( server );
wss.on('connection', (ws) =>
ws.id = uuid.v4(); // This is the relevant line of code
ws.on('message', (msg: string) =>
...
);
For net.Socket:
Quite the same - according to this, the following is required:
var server = net.createServer();
server.on('connection', function(conn)
conn.id = uuid.v4(); // This is the relevant line of code
conn.on('data', function(data)
...
);
);
The problem
The error "Property 'id' does not exist on type 'WebSocket' [or 'Socket' accordingly]" during compilation. This explains why.
Optional Solution #1: Cast to any
The update net.Socket code will be:
var server = net.createServer();
server.on('connection', function(conn)
(conn as any).id = uuid.v4();
conn.on('data', function(data)
console.log('Session id:' + (conn as any).id);
);
);
The problem: It doesn't seem like good practice to me. I don't have references for why except for a hunch for now.
Optional Solution #2: Use a local variable [seems like a better option]
The update net.Socket code will be:
var server = net.createServer();
server.on('connection', function(conn)
const id: string = uuid.v4();
conn.on('data', function(data)
console.log('Session id:' + id);
);
);
After some experiencing, it seems to work properly.
So - the questions:
In optional solution #2: is it guaranteed that the id variable will always be available in this scope? In other words: is this solution valid? for both net.Socket & Websocket? Or is there something that I'm missing?
In general: Is there additional identifiers (perhaps built in identifiers in WebSocket and net.Socket) that can be used instead?
[Typescript version: 3.2.4].
node.js typescript sockets websocket
node.js typescript sockets websocket
edited Mar 9 at 14:40
Louis
96.8k22184237
96.8k22184237
asked Mar 7 at 9:59
MaoritzioMaoritzio
5202623
5202623
1
for 1, it's valid solution, check this developer.mozilla.org/en-US/docs/Web/JavaScript/Closures
– Tubc
Mar 9 at 10:56
add a comment |
1
for 1, it's valid solution, check this developer.mozilla.org/en-US/docs/Web/JavaScript/Closures
– Tubc
Mar 9 at 10:56
1
1
for 1, it's valid solution, check this developer.mozilla.org/en-US/docs/Web/JavaScript/Closures
– Tubc
Mar 9 at 10:56
for 1, it's valid solution, check this developer.mozilla.org/en-US/docs/Web/JavaScript/Closures
– Tubc
Mar 9 at 10:56
add a comment |
1 Answer
1
active
oldest
votes
I'm not aware of a field that already exists for that.
If you can keep the socket id in a local variable like you do in option 2, that's what I'd do. I generally prefer to avoid adding arbitrary fields to objects. However, sometimes you want the entirety of your application to be able to access the additional piece of data, and in those cases using a local variable won't work.
Adding a custom field
Instead of using a type assertion to any, you could add a file to your project that contains this:
declare module "net"
interface Socket
id: string;
This is augmenting the net.Socket interface to add an id field which is a string. This is a bit neater than a type assertion because the type assertion would let typos go through (e.g. (conn as any).ids). I used your code, removed the type assertion and added the above in a file named externals.d.ts that I put next to the .ts file that contains your code. tsc stopped complaining about the field. Note that you don't need to import this file or refer to it in any way. You must just have a tsconfig.json that picks it up along with the rest of your source. By default, it would be picked up due to the .d.ts extension.
In the past I've used type assertions and interface augmentation to add arbitrary fields to DOM nodes, and it worked just fine. However, when I did that, I used field names that were very singular, meaning that there was a very low chance of a clash with other libraries that might want to add their own fields. Your field name is id. I'd be worried about name clashes with other libraries that decide they want to keep track of sockets and add their own id field to a socket.
Using WeakMap
There's another method you can use. You could setup a WeakMap that associates the socket with the id. Here's an illustration. You could have a module socket-map that just exports a map that maps sockets to strings:
import * as net from "net";
export const socketMap = new WeakMap<net.Socket, string>();
And then you'd store the socket with the id when you obtain the socket:
import * as net from "net";
import * as uuid from "uuid";
import socketMap from "./socket-map";
var server = net.createServer();
server.on('connection', function(conn)
const id = uuid.v4();
socketMap.set(conn, id); // You store the socket into the map.
conn.on('data', function(data)
console.log('Session id:' + (conn as any).id);
);
);
Then later, in another module, you could get the id back with:
import * as net from "net";
import socketMap from "./socket-map";
export function foo(conn: net.Socket)
const id = socketMap.get(conn);
Here I've just associated the socket with an id string, but you could have any structure you want in the values of the WeakMap. It could be an object that contains a whole slew of information besides an id.
The reason to use WeakMap is while the keys of a WeakMap object contain references to objects, these references do not count as far as garbage collection goes. So if your application is done with a socket and no longer references it anywhere than a WeakMap, the reference present in the WeakMap will still allow the socket to be collected by the garbage collector.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55040899%2fassigning-websocket-and-net-socket-with-unique-id%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I'm not aware of a field that already exists for that.
If you can keep the socket id in a local variable like you do in option 2, that's what I'd do. I generally prefer to avoid adding arbitrary fields to objects. However, sometimes you want the entirety of your application to be able to access the additional piece of data, and in those cases using a local variable won't work.
Adding a custom field
Instead of using a type assertion to any, you could add a file to your project that contains this:
declare module "net"
interface Socket
id: string;
This is augmenting the net.Socket interface to add an id field which is a string. This is a bit neater than a type assertion because the type assertion would let typos go through (e.g. (conn as any).ids). I used your code, removed the type assertion and added the above in a file named externals.d.ts that I put next to the .ts file that contains your code. tsc stopped complaining about the field. Note that you don't need to import this file or refer to it in any way. You must just have a tsconfig.json that picks it up along with the rest of your source. By default, it would be picked up due to the .d.ts extension.
In the past I've used type assertions and interface augmentation to add arbitrary fields to DOM nodes, and it worked just fine. However, when I did that, I used field names that were very singular, meaning that there was a very low chance of a clash with other libraries that might want to add their own fields. Your field name is id. I'd be worried about name clashes with other libraries that decide they want to keep track of sockets and add their own id field to a socket.
Using WeakMap
There's another method you can use. You could setup a WeakMap that associates the socket with the id. Here's an illustration. You could have a module socket-map that just exports a map that maps sockets to strings:
import * as net from "net";
export const socketMap = new WeakMap<net.Socket, string>();
And then you'd store the socket with the id when you obtain the socket:
import * as net from "net";
import * as uuid from "uuid";
import socketMap from "./socket-map";
var server = net.createServer();
server.on('connection', function(conn)
const id = uuid.v4();
socketMap.set(conn, id); // You store the socket into the map.
conn.on('data', function(data)
console.log('Session id:' + (conn as any).id);
);
);
Then later, in another module, you could get the id back with:
import * as net from "net";
import socketMap from "./socket-map";
export function foo(conn: net.Socket)
const id = socketMap.get(conn);
Here I've just associated the socket with an id string, but you could have any structure you want in the values of the WeakMap. It could be an object that contains a whole slew of information besides an id.
The reason to use WeakMap is while the keys of a WeakMap object contain references to objects, these references do not count as far as garbage collection goes. So if your application is done with a socket and no longer references it anywhere than a WeakMap, the reference present in the WeakMap will still allow the socket to be collected by the garbage collector.
add a comment |
I'm not aware of a field that already exists for that.
If you can keep the socket id in a local variable like you do in option 2, that's what I'd do. I generally prefer to avoid adding arbitrary fields to objects. However, sometimes you want the entirety of your application to be able to access the additional piece of data, and in those cases using a local variable won't work.
Adding a custom field
Instead of using a type assertion to any, you could add a file to your project that contains this:
declare module "net"
interface Socket
id: string;
This is augmenting the net.Socket interface to add an id field which is a string. This is a bit neater than a type assertion because the type assertion would let typos go through (e.g. (conn as any).ids). I used your code, removed the type assertion and added the above in a file named externals.d.ts that I put next to the .ts file that contains your code. tsc stopped complaining about the field. Note that you don't need to import this file or refer to it in any way. You must just have a tsconfig.json that picks it up along with the rest of your source. By default, it would be picked up due to the .d.ts extension.
In the past I've used type assertions and interface augmentation to add arbitrary fields to DOM nodes, and it worked just fine. However, when I did that, I used field names that were very singular, meaning that there was a very low chance of a clash with other libraries that might want to add their own fields. Your field name is id. I'd be worried about name clashes with other libraries that decide they want to keep track of sockets and add their own id field to a socket.
Using WeakMap
There's another method you can use. You could setup a WeakMap that associates the socket with the id. Here's an illustration. You could have a module socket-map that just exports a map that maps sockets to strings:
import * as net from "net";
export const socketMap = new WeakMap<net.Socket, string>();
And then you'd store the socket with the id when you obtain the socket:
import * as net from "net";
import * as uuid from "uuid";
import socketMap from "./socket-map";
var server = net.createServer();
server.on('connection', function(conn)
const id = uuid.v4();
socketMap.set(conn, id); // You store the socket into the map.
conn.on('data', function(data)
console.log('Session id:' + (conn as any).id);
);
);
Then later, in another module, you could get the id back with:
import * as net from "net";
import socketMap from "./socket-map";
export function foo(conn: net.Socket)
const id = socketMap.get(conn);
Here I've just associated the socket with an id string, but you could have any structure you want in the values of the WeakMap. It could be an object that contains a whole slew of information besides an id.
The reason to use WeakMap is while the keys of a WeakMap object contain references to objects, these references do not count as far as garbage collection goes. So if your application is done with a socket and no longer references it anywhere than a WeakMap, the reference present in the WeakMap will still allow the socket to be collected by the garbage collector.
add a comment |
I'm not aware of a field that already exists for that.
If you can keep the socket id in a local variable like you do in option 2, that's what I'd do. I generally prefer to avoid adding arbitrary fields to objects. However, sometimes you want the entirety of your application to be able to access the additional piece of data, and in those cases using a local variable won't work.
Adding a custom field
Instead of using a type assertion to any, you could add a file to your project that contains this:
declare module "net"
interface Socket
id: string;
This is augmenting the net.Socket interface to add an id field which is a string. This is a bit neater than a type assertion because the type assertion would let typos go through (e.g. (conn as any).ids). I used your code, removed the type assertion and added the above in a file named externals.d.ts that I put next to the .ts file that contains your code. tsc stopped complaining about the field. Note that you don't need to import this file or refer to it in any way. You must just have a tsconfig.json that picks it up along with the rest of your source. By default, it would be picked up due to the .d.ts extension.
In the past I've used type assertions and interface augmentation to add arbitrary fields to DOM nodes, and it worked just fine. However, when I did that, I used field names that were very singular, meaning that there was a very low chance of a clash with other libraries that might want to add their own fields. Your field name is id. I'd be worried about name clashes with other libraries that decide they want to keep track of sockets and add their own id field to a socket.
Using WeakMap
There's another method you can use. You could setup a WeakMap that associates the socket with the id. Here's an illustration. You could have a module socket-map that just exports a map that maps sockets to strings:
import * as net from "net";
export const socketMap = new WeakMap<net.Socket, string>();
And then you'd store the socket with the id when you obtain the socket:
import * as net from "net";
import * as uuid from "uuid";
import socketMap from "./socket-map";
var server = net.createServer();
server.on('connection', function(conn)
const id = uuid.v4();
socketMap.set(conn, id); // You store the socket into the map.
conn.on('data', function(data)
console.log('Session id:' + (conn as any).id);
);
);
Then later, in another module, you could get the id back with:
import * as net from "net";
import socketMap from "./socket-map";
export function foo(conn: net.Socket)
const id = socketMap.get(conn);
Here I've just associated the socket with an id string, but you could have any structure you want in the values of the WeakMap. It could be an object that contains a whole slew of information besides an id.
The reason to use WeakMap is while the keys of a WeakMap object contain references to objects, these references do not count as far as garbage collection goes. So if your application is done with a socket and no longer references it anywhere than a WeakMap, the reference present in the WeakMap will still allow the socket to be collected by the garbage collector.
I'm not aware of a field that already exists for that.
If you can keep the socket id in a local variable like you do in option 2, that's what I'd do. I generally prefer to avoid adding arbitrary fields to objects. However, sometimes you want the entirety of your application to be able to access the additional piece of data, and in those cases using a local variable won't work.
Adding a custom field
Instead of using a type assertion to any, you could add a file to your project that contains this:
declare module "net"
interface Socket
id: string;
This is augmenting the net.Socket interface to add an id field which is a string. This is a bit neater than a type assertion because the type assertion would let typos go through (e.g. (conn as any).ids). I used your code, removed the type assertion and added the above in a file named externals.d.ts that I put next to the .ts file that contains your code. tsc stopped complaining about the field. Note that you don't need to import this file or refer to it in any way. You must just have a tsconfig.json that picks it up along with the rest of your source. By default, it would be picked up due to the .d.ts extension.
In the past I've used type assertions and interface augmentation to add arbitrary fields to DOM nodes, and it worked just fine. However, when I did that, I used field names that were very singular, meaning that there was a very low chance of a clash with other libraries that might want to add their own fields. Your field name is id. I'd be worried about name clashes with other libraries that decide they want to keep track of sockets and add their own id field to a socket.
Using WeakMap
There's another method you can use. You could setup a WeakMap that associates the socket with the id. Here's an illustration. You could have a module socket-map that just exports a map that maps sockets to strings:
import * as net from "net";
export const socketMap = new WeakMap<net.Socket, string>();
And then you'd store the socket with the id when you obtain the socket:
import * as net from "net";
import * as uuid from "uuid";
import socketMap from "./socket-map";
var server = net.createServer();
server.on('connection', function(conn)
const id = uuid.v4();
socketMap.set(conn, id); // You store the socket into the map.
conn.on('data', function(data)
console.log('Session id:' + (conn as any).id);
);
);
Then later, in another module, you could get the id back with:
import * as net from "net";
import socketMap from "./socket-map";
export function foo(conn: net.Socket)
const id = socketMap.get(conn);
Here I've just associated the socket with an id string, but you could have any structure you want in the values of the WeakMap. It could be an object that contains a whole slew of information besides an id.
The reason to use WeakMap is while the keys of a WeakMap object contain references to objects, these references do not count as far as garbage collection goes. So if your application is done with a socket and no longer references it anywhere than a WeakMap, the reference present in the WeakMap will still allow the socket to be collected by the garbage collector.
answered Mar 9 at 14:31
LouisLouis
96.8k22184237
96.8k22184237
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55040899%2fassigning-websocket-and-net-socket-with-unique-id%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
for 1, it's valid solution, check this developer.mozilla.org/en-US/docs/Web/JavaScript/Closures
– Tubc
Mar 9 at 10:56