- 论坛徽章:
- 0
|
客户端
#!/usr/bin/env python
#coding=utf-8
import cmd
import sys
import socket,time,random
import thread
HOST = '61.129.51.204'
PORT = 4657 # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
print "lease Enter Your NickName:"
nickname=raw_input()
print "Your Nickname is:%s"%nickname
s.send('<main_action>setNickName</main_action><nickname>%s</nickname>'%nickname)
class UI(cmd.Cmd):
Last_mail_file = ""
def __init__(self):
cmd.Cmd.__init__(self)
self.do_hello(self)
self.prompt = ''
def do_hello(self, arg):
print "********************************************"
print "Client"
print "********************************************"
def do_quit(self, arg):
print "byebye"
sys.exit(1)
def do_exit(self, arg):
print "byebye"
sys.exit(1)
def default(self, line):
#print "You Said:",line
info="<main_action>sendMsg</main_action><nickname>%s</nickname><msg>%s</msg>"%(nickname,line)
s.send(info)
def do_C2S(self,arg):
print arg
class CSC(UI):
def __init__(self):
pass
def run(self,a):
while 1:
data = s.recv(204
if len(data)>1:
self.do_C2S(data)
def main():
a = UI()
c=CSC()
thread.start_new(c.run,(1,))
a.cmdloop()
if __name__ == '__main__':
main() |
|