python 套接字简单服务器端

#coding:utf-8
import threading
import os, os.path, sys
import win32process, win32event
import socket
handle = 0
hProcess=0
hThread=0
dwProcessId=0
dwThreadId =0

mpath = "c:\\Release"
mexe = "cefclient.exe"

def runexe(a):
    try :
            hProcess, hThread, dwProcessId, dwThreadId = win32process.CreateProcess(os.path.join(mpath, mexe),
                    '', None, None, 0,
                    win32process.CREATE_NO_WINDOW,
                    None ,
                    mpath,
                    win32process.STARTUPINFO())
            #win32api.CloseHandle(hThread)
    except Exception, e:
            print "Create Error!"
            handle = None


th1 = threading.Thread(target=runexe, args=(1,))
th1.setDaemon(True)
th1.start()

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(('localhost', 49677))
sock.listen(5)
while True:
    connection,address = sock.accept()
    try:
        connection.settimeout(5)
        buf = connection.recv(1024)
        uro = ("%s" % buf)
        print uro
        if (uro.find(":") > -1):
            print "a"
            #command = 'taskkill /f /im cefclient.exe'

            #os.system(command)


    except socket.timeout:
        print 'time out'

    connection.close()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值