一个 socket 客户端类 怎么调用 引用

2015-11-02 21:36:56 +08:00
 617450941
import sys
import thread
import server_pool
import db_transfer
import threading
import socket
from server_pool import ServerPool
import Config

class Connect(object):
#发送数据
def DealOut(s):
global nick, outString
while True:
outString = raw_input()
outString = nick + ': ' + outString
s.send(outString)

#接收数据
def DealIn(s):
global inString
while True:
try:
inString = s.recv(1024)
if not inString:
break
if outString != inString:
print inString
if inString == str(25352):
ServerPool.get_instance().del_server(25352)
except:
break

def defcon():
inString = ''
outString = ''
nick = ''
ip = Config.MASTER_SERVER_IP
port = Config.MASTER_SERVER_PORT
nick = Config.SERVER_NAME
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(("0.0.0.0", Config.CLIENT_PORT))
sock.connect((ip, port))
sock.send(nick)

thin = threading.Thread(target = DealIn, args = (sock,))
thin.start()
thout = threading.Thread(target = DealOut, args = (sock,))
thout.start()

另一个类想调用这里面的函数方法 该怎么调用 我试了好多尝试都调用不成功 无法成功运行 只能单独一个不是类的 py 文件里运行 改成类调用 就用不了了 只想实现需要时可以调用里面的方法发送数据 或者接收数据之类的
2140 次点击
所在节点    Python
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/233053

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX