Python Twisted Client

Interface Of The Protocol Class

While investigating the possible uses for the Twisted Networking Engine, I found it hard to find examples that describe the Interface of the Protocol class. So, I will share this brief code snippet with you.

Protocol Class

A Protocol class can have the following methods for event-driven TCP connections:

MyProtocol(Protocol):         

  def makeConnection(self, transport):
    ''' code '''         

  def connectionMade(self):
    ''' code '''

  def dataReceived(self, data):
    '''' code ''''

  def connectionLost(self, reason):
    ''' code '''

Read full article here >>

Node.js Example

Node.js is a server-side JavaScript framework used for developing event-driven networking programs for concurrency rather then threading.

var net = require('net');
port = 8001;

net.createServer(function (stream) {
  stream.setEncoding('utf8');

  stream.on('connect', function () {
    stream.write('hi, Your connected to my TCP Server!');
  });  

  stream.on('data', function (data) {
    stream.write('Writing network data..');
  });

  stream.on('end', function () {
    stream.write("bye bye");
    stream.end();
  });

}).listen(port, "localhost");

console.log("Server started at port "+port);

Read full article here >>