V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
617450941
V2EX  ›  Python

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

  •  
  •   617450941 · 2015-11-02 21:36:56 +08:00 · 2094 次点击
    这是一个创建于 3103 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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 文件里运行 改成类调用 就用不了了 只想实现需要时可以调用里面的方法发送数据 或者接收数据之类的
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2282 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 47ms · UTC 08:56 · PVG 16:56 · LAX 01:56 · JFK 04:56
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.