Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to detect which client is receiving the package? #1656

Open
legionir opened this issue Dec 18, 2023 · 0 comments
Open

How to detect which client is receiving the package? #1656

legionir opened this issue Dec 18, 2023 · 0 comments

Comments

@legionir
Copy link

legionir commented Dec 18, 2023

Hello,

I am creating a WebSocket proxy. And I need to know which client is receiving the package. Basically I should store data from incoming traffic to use them in outgoing traffic and each client has different data. I searched and tried different ways but none of them worked. Can anyone suggest a working solution?

var proxyWebsocket, serverWebsocket, clientData = {};
const startWSProxy = (data) => {
	proxyWebsocket = new httpProxy.createProxyServer({
		target: {
			protocol: 'ws',
			host: 'localhost',
			port: localPacketPort
		},
		ws: true,
		xfwd: true,
		toProxy: true
	});

	proxyWebsocket.on('open', function (proxySocket) {

		proxySocket.on('data', (res) => {
			// access the identifier here
			// For example:
			// proxySocket._uuid
			// console.log(clientData[proxySocket._uuid]);
		});
	});

	serverWebsocket = http.createServer();
	serverWebsocket.on('upgrade', function (req, socket, head) {
   proxyWebsocket.ws(req, socket, head);
		// Set an identifier here
		// For example:
		// socket._uuid = uuid_generate();
		socket.on('data', (res) => {
			// clientData[socket._uuid][] = res
		});
	});

	serverWebsocket.listen(remotePacketPort);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant