[Tutor] A very simple socket server question

Kevin python.programming at gmail.com
Tue Mar 29 20:04:08 CEST 2005


I figured out how to create a very simple socket server. Though this
socket server does exactly nothing special. I can however get it to
send only one line of data back to the telnet client.

import socket
######################
HOST = ""
PORT = 4000
######################

s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.bind((HOST,PORT))
s.listen(5)
def log():
	a = addr
	b = str(a)
	logfile = open("logfile.log", "a+")
	logfile.write("Attempting connection from "+b+"\n")
	logfile.close()

while 1:
	conn, addr = s.accept()
	data = conn.recv(1024)
        if not data:
              break
        else:
              conn.send(data)

How can I make it so that when a client sends the word hello the
server will write back
hello, how are you?.

Thanks
Kevin


More information about the Tutor mailing list