LineReceiver Protocol In Twisted

Basic Line Receiver

from twisted.internet import protocol, reactor
from twisted.protocols import basic

class LineProtocol(basic.LineReceiver):

  def lineReceived(self, line):
    self.transport.write('You sent me this: '+line)
    self.transport.loseConnection()

class LineFactory(protocol.ServerFactory):
  protocol = LineProtocol

reactor.listenTCP(8001), LineFactory())
reactor.run()

Read full article here >>

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 >>

An Objective-C Example On Optimization

Multiple Choice

Out of the following three code snippets, only one is optimized. Which snippet is it?

Snippet 1

for (object in objects) {

  if ( [object tag] == kTagObjectOne ) {
    [object foo];
  }
  [object bar];
}

Snippet 2

for (object in objects) {

  if ( [object tag] == kTagObjectOne ) {

    [object foo];
    [object bar];

  } else {

    [object bar];

  }
}

Snippet 3

for (object in objects) {

 if ([object tag] != kTagObjectOne )
   [object bar];

}

object = [objects getChildByTag:kTagObjectOne];

if (object) {

  [object foo];
  [object bar];

}

Read full article here >>

ELECTRONIC ARTS, INC. (Origin Store)

ELECTRONIC ARTS, INC. (Origin Store)

Order Battlefield 3 from Origin and get the SPECACT Kit & Dog Tag Bundle for PC as a bonus