Reputation: 11
I want to create a meteor application that connect meteor server to another tcp server, that is meteor server is client side and another tcp server is server side.
1.It like WebSocket of browser ,but I want use it on meteor server ,not on meteor client . WebSocket using like :
var tcpServer = "ws://some.tcpServer.org/";
socket = new WebSocket(tcpServer,options);
socket.onopen = function(evt) { onOpen(evt) };
socket.onclose = function(evt) { onClose(evt) };
socket.onmessage = function(evt) { onMessage(evt) };
socket.onerror = function(evt) { onError(evt) };
2.Maybe as follow :
if (Meteor.isServer) {
Meteor.startup(function () {
var tcpServer = "ws://some.tcpServer.org/";
socket = new socketClient(tcpServer,options);
socket.onopen = function(evt) { onOpen(evt) };
socket.onclose = function(evt) { onClose(evt) };
socket.onmessage = function(evt) { onMessage(evt) };
socket.onerror = function(evt) { onError(evt) };
})
}
3.Or ...
var net = Npm.require('net');
net.createServer(function(socket){...} is for server side , not fit for my idea.
Maybe like net.createClient(function(tcpServer, options ){...} , but no this method.
I had been looking around but i do not see a method for Meteor. Can anyone give any pointers for me to start?
Thank a lot !
Upvotes: 0
Views: 1338
Reputation: 638
Here you have link to working plugin:
websocketify on atmosphere.com
Upvotes: 0
Reputation: 36900
There are several problems with what you described.
WebSocket, which works over HTTP, and TCP are completely different protocols. You will not be able to open a WebSocket connection to a TCP server.
To have the Meteor server communicate with another server over TCP, you'll want to use Node's net API. To use this with Meteor, you'll need to use async callbacks in a way that is compatible with Fibers; see this blog post for an overview and https://stackoverflow.com/a/21542356/586086.
Upvotes: 1