how to efficienty transfer file between 2 node.js instances?

I'm developing chat application using app.js which is webkit+node.js framework. So i have node.js plus bridged web browser environment on both sides. I want to make file transfer feature somewhat similar to Skype one.

So, initial idea is to:

1.connect clients to main server.

2.Each client gets ip of oposite ones.

3.Start socket or websocket server on both clients and connect to each other.

4.Sender reads the file and transmits it to the reciver.

Question are:

1.Im not really sure that one client can "see" the other.

2.file is a binary data, but websockets are made for text messages so i need some kind of coding/decoding stuff. I thought about base 64 but it has 30% of "overhead" information. So i need something more effitient (base 128?).

3.If it is not efficient to use websocket should i use TCP sockets instead? What problems can appear if i decide to use them?

Yeah i know about node2node and BinaryJS, i just dont know should i use them or not. And i really what to do something myself.

OK, with your communication looking like this:

(C->N)<->N<->(N->C)

(...) is installed on one client's machine. N's are node servers, C's are web clients.

  1. This is out of your control. Some file sharing apps send test packets from the central server to clients, to check whether ports are open and NAT rules are configured correctly, etc. Your clients will start their own servers on some port, your master server can potentially create a test connection to these servers to see whether they're started correctly and open to the web, BEFORE telling other clients that they can send files.

  2. Websockets are great for status messages from your servers to the web GUIs and general client-to-client communication. For the actual file transfers, I would use TCP sockets, see the next answer. On the other hand base64 encoding is really not a slow process, play with it and benchmark its performance, then decide with some data to back up your decision.

  3. You could use a combination: websockets from your servers to the web GUIs, but TCP communication between the servers themselves. TCP servers (and streams) aren't hard to set up in Node, I see no disadvantages. It might actually be less complicated than installing node2node on those servers, since TCP is already built-in.