How can I create my own protocol as well as HTTP?

Asked

Viewed 806 times

1

See this code below. It creates a server with Node.js. But, if I change var http for example: var xyz = require ("xyz"), var server = xyz.createserver... makes a mistake.

var http = require("http");
var server = http.createServer(function(request, response) {
  response.writeHead(200, {"Content-Type": "text/html"});
  response.write("<!DOCTYPE "html">");
  response.write("<html>");
  response.write("<head>");
  response.write("<title>Hello World Page</title>");
  response.write("</head>");
  response.write("<body>");
  response.write("Hello World!");
  response.write("</body>");
  response.write("</html>");
  response.end();
});

server.listen(80);
console.log("Server is listening");
  • 1

    Maybe because creating a protocol is way beyond just renaming it? When you use the require you are "calling a file", it is as if you inform "I’m gonna need to use this library". Then you start using what it offers, which is a set of functions that someone developed and you use. When you use xyz it doesn’t exist, so you can’t use it. If you really want to create a new protocol I believe that will take a long way to it.

  • Thanks for your reply. I’m new to Node.js and tals. I still need to know a lot of things.

  • There are several levels and protocol. Even, there are protocols on protocols. The TCP/IP itself (good barte of our current internet) works on 5 main layers of protocol: 1. physical layer; 2. link/jump bed (ethernet/ATM); 3. network layer (IP); 4. transport layer (TCP/UDP); 5. application layer (HTTP/FTP/SSH etc). I have personally written some protocols on HTTP (HTTP use as a base) and also had to reverse engineer an undocumented protocol (from work) that worked directly on TCP. I can answer with that if you wish

  • In addition to my comment: when I read the title of the question, I interpreted it as being about protocols in a generic way, there was no attack on me being connected with node.js.

  • 1

    @teves-rei The answer solved your doubt? Do you think you can accept it? See the [tour] if you do not know how. This would help a lot to indicate that the solution was useful for you. You can also vote on any question or answer you find useful on the entire site (when you have 15 points).

1 answer

2

With much study of the fundamentals of computing.

Well, simply, write down on a paper what you want it to do, what operations, how is the format of the messages, the errors, how to deal with each situation. You’ll already have a protocol.

After specified need to implement it.

But, no, no, no! If not even the most experienced programmers are creating protocols except in case of extreme need, do not try this at home, nor with adult supervision :)

Behold: In what language was HTTP written?.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.