socket troubles

Sean Conley sconley at
Mon Feb 14 07:21:57 CET 2000

This problem has me completely stumped.  I am trying to write a telnet
client (actually a mud client) in Python.  The problem is that I can
connect and read information from the socket, but nothing seems to
happen when I send to the socket.  I believe it may be a problem with my
program, as I had the same problem with Perl/Tk and was unable to solve
it there either.  So, if anyone has ANY idea why this could be please
email me or post here.  Forgive any horrible syntax as this is my first
attempt at a python program and I am just trying to get the skeleton,
and the most important part of the program working before I start
cleaning it up.  Anyhow, here is the code: 


from Tkinter import *
from _tkinter import *
from socket import *
from string import *
from re import *

#*** Get input from the socket and post it to the screen
def readsock(*args):
  data = s.recv(80)

  #*** Telnet arbitration stuff here
  if compile(chr(255)).search(data):
    print "IAC\n"

  textbox.insert(index="insert", chars=data)

#*** Write to the socket
def writesock(*args):
  global contents
  info = contents.get()

#*** Declare some variables
HOST = ''
PORT = 3000

#*** Set up what it looks like
root = Tk()

outputscroll = Scrollbar(root)
textbox = Text(root)
inputbox = Entry(root)

textbox.config(yscrollcommand=outputscroll, state="disabled")

contents = StringVar()
inputbox["textvariable"] = contents

inputbox.bind(sequence="<Return>", func=writesock)

inputbox.pack(side="bottom", fill="x")
outputscroll.pack(side="right", fill="y")
textbox.pack(expand=1, fill="both")

s = socket(AF_INET, SOCK_STREAM)
s.connect(HOST, PORT)

createfilehandler(s, READABLE, readsock)


More information about the Python-list mailing list