Domanda

I understand that the Http protocol is different from the Telnet protocol. Both are a layer above the net module in node.js. So if I create a Telnet server chat application, does that mean I can't serve http to the browser? I want to have a web client that connects to the telnet chat server.

Is it possible to write two applications: one web server, and one telnet server. Then connect the web server to the telnet server? Would this be the logical way to create a web client for the telnet server?

È stato utile?

Soluzione

To write a telnet chat app in node.js would require you to use raw sockets. (http://nodejs.org/api/net.html#net_class_net_socket)

Http runs over TCP (sockets).

Can you do both? Well, yes, but not exactly easily. The issue is both http and telnet would create the socket connection, but the telnet client wouldn't do anything else until told to, whereas http would send the http request.

You could use the lack of the request for some period of time to be an indicator of telnet client, but the second issue is that it means you have to manually receive and reply for the http requests.

Altri suggerimenti

chat server with node.js? you mean something like socket.io ?

anyway, lets see...

$ curl http://localhost
<html><body><h1>It works!</h1>
<p>This is the default web page for this server.</p>
<p>The web server software is running but no content has been added, yet.</p>
</body></html>
$ telnet localhost 80
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET
<html><body><h1>It works!</h1>
<p>This is the default web page for this server.</p>
<p>The web server software is running but no content has been added, yet.</p>
</body></html>
Connection closed by foreign host.

so I guess you can, the question is why would you? :)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top