TCP server

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • assaf

    #1

    TCP server

    i am try to create a server
    what am i suppose to send to SocketServer.TC PServer
    what is the client_address ("127.0.0.1: 80" ?)
    and BaseRequestHand ler = ?

    thanks

  • Pedro Werneck

    #2
    Re: TCP server


    A quick example for you:

    ###
    import SocketServer


    class EchoRequestHand ler(SocketServe r.BaseRequestHa ndler):
    def setup(self):
    print self.client_add ress, 'connected!'
    self.request.se nd('hi ' + str(self.client _address) + '\n')

    def handle(self):
    while 1:
    data = self.request.re cv(1024)
    self.request.se nd(data)
    if data.strip() == 'bye':
    return

    def finish(self):
    print self.client_add ress, 'disconnected!'
    self.request.se nd('bye ' + str(self.client _address) + '\n')

    #server host is a tuple ('host', port)
    server = SocketServer.Th readingTCPServe r(('', 5000), EchoRequestHand ler)
    server.serve_fo rever()

    ###

    Telnet to localhost 5000 and any data you sent will be echoed back to you... send 'bye' and the connection is closed




    On 24 Jan 2005 06:25:18 -0800
    "assaf" <assafs@ixi.com > wrote:
    [color=blue]
    > i am try to create a server
    > what am i suppose to send to SocketServer.TC PServer
    > what is the client_address ("127.0.0.1: 80" ?)
    > and BaseRequestHand ler = ?
    >
    > thanks
    >
    > --
    > http://mail.python.org/mailman/listinfo/python-list[/color]

    Comment

    • Dennis Lee Bieber

      #3
      Re: TCP server

      On 24 Jan 2005 06:25:18 -0800, "assaf" <assafs@ixi.com > declaimed the
      following in comp.lang.pytho n:
      [color=blue]
      > i am try to create a server
      > what am i suppose to send to SocketServer.TC PServer[/color]

      I'll let others explain (I've not used it), but...
      [color=blue]
      > what is the client_address ("127.0.0.1: 80" ?)[/color]

      Localhost/loopback address, HTTP port. Planning to create a
      web-server, perhaps?

      --[color=blue]
      > =============== =============== =============== =============== == <
      > wlfraed@ix.netc om.com | Wulfraed Dennis Lee Bieber KD6MOG <
      > wulfraed@dm.net | Bestiaria Support Staff <
      > =============== =============== =============== =============== == <
      > Home Page: <http://www.dm.net/~wulfraed/> <
      > Overflow Page: <http://wlfraed.home.ne tcom.com/> <[/color]

      Comment

      Working...