Subversion Repositories pytwidcpp

Rev

Rev 3 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3 Rev 4
Line 5... Line 5...
5
from twisted.python import log
5
from twisted.python import log
6
6
7
import socket
7
import socket
8
import re
8
import re
9
9
10
class NMDC(protocol.Protocol):
10
class NMDC(basic.LineReceiver):
11
    """
11
    """
12
    NMDC Protocol implementation
12
    NMDC Protocol implementation
13
    """
13
    """
14
14
-
 
15
    delimiter = "|"
-
 
16
15
    buffer = ""
17
    buffer = ""
16
    encoding = None
18
    encoding = None
17
    hostname = None
19
    hostname = None
18
20
19
    def dataReceived(self, data):
21
    def lineReceived(self, line):
20
        print "Data: %s" % data
-
 
21
        lines = (self.buffer + data).split("|")
-
 
22
        print self.buffer
-
 
23
        for line in lines:
-
 
24
            if len(line) <= 2:
-
 
25
                continue
-
 
26
            print "Line: %s" % line
22
        print "Line Received: %s" % line
27
            command, params = self.parseLine(line)
23
        command, params = self.parseLine(line)
28
        self.handleCommand(command, params)
24
        self.handleCommand(command, params)
29
25
30
    def connectionLost(self, reason):
26
    def connectionLost(self, reason):
31
        print "Conlost: %s" %self
27
        print "Conlost: %s" %self
32
        pass
-
 
33
28
34
    def connectionMade(self):
29
    def connectionMade(self):
35
        print "Made connect"
30
        print "Made connect"
36
        if self.hostname is None:
31
        if self.hostname is None:
37
            self.hostname = socket.getfqdn()
32
            self.hostname = socket.getfqdn()