小编Dar*_*r56的帖子

在Python中侦听连接时接收命令行输入

我正在尝试编写一个程序,让客户端连接到它,而服务器仍然能够向所有客户端发送命令.我正在使用"Twisted"解决方案.我怎么能这样做?这是我到目前为止的代码(我知道Twisted已经使用了非阻塞套接字):

import threading
print 'threading.'

def dock():
   try:
       from twisted.internet.protocol import Factory, Protocol
       from twisted.internet import reactor
       import currentTime
       print '[*]Imports succesful.'
   except:
       print '[/]Imports failed.'

   #Define the class for the protocol
   class Master(Protocol):
       command = raw_input('> ')
       def connectionMade(self):
           print 'Slave connected.'
           print currentTime.getTime() #Print current time
           #self.transport.write("Hello")

       def connectionLost(self, reason):
           print 'Lost.'
   #Assemble it in a "factory"

   class MasterFactory(Factory):
       protocol = Master


   reactor.listenTCP(8800, MasterFactory())

   #Run it all
   reactor.run()

def commandline():
   raw_input('>')

threading.Thread(target=dock()).start()
threading.Thread(target=commandline()).start()
Run Code Online (Sandbox Code Playgroud)

python sockets client twisted

6
推荐指数
1
解决办法
1190
查看次数

使用Java扫描WiFi

如何用Java扫描WiFi网络?我一直在寻找谷歌,但我能找到的唯一片段是Android操作系统.

java wifi network-scan

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

client ×1

java ×1

network-scan ×1

python ×1

sockets ×1

twisted ×1

wifi ×1