zoukankan      html  css  js  c++  java
  • python socket超时

    [root@yyjk ~]# time python a1.py
    Mon May  7 09:32:31 2018
    a
    1
    <type 'str'>
    a
    <type 'str'>
    1
    Traceback (most recent call last):
      File "a1.py", line 46, in <module>
        a.Sms('a',18072722237)
      File "a1.py", line 27, in Sms
        s.connect((host,port))
      File "/usr/local/lib/python2.7/socket.py", line 224, in meth
        return getattr(self._sock,name)(*args)
    socket.timeout: timed out
    
    real	0m40.076s
    user	0m0.031s
    sys	0m0.007s
    [root@yyjk ~]# vim a1.py
    [root@yyjk ~]# cat a1.py
    # -*- coding: utf-8 -*-
    import SocketServer
    import socket
    import time
    import sys
    reload(sys)
    print time.ctime()
    sys.setdefaultencoding('utf-8')
    class SMSsendx (object):
      def Sms(self,a,b):
         message=a
         phone=b
         #.decode('utf-8').encode('gbk')
         print a
         print len(message)
         print type(message)
         message=message.encode('gbk')
         print message
         print type(message)
         print len(message)
         host='10.3.229.91'
         port=745
         bufsize=1024
         addr=(host,port)
         s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
         s.settimeout(40)
         s.connect((host,port))
         data=""
         tab=chr(9)
         #my $data=^Xd$tab;
         data=chr(28)+chr(48)+chr(88)+chr(100)+tab
         data +='015802'+tab
         data +=tab
         data +='N'+tab
         data +=message+tab
         print data
         data +=str(phone)+tab
         #msg = data.encode('gbk')
         s.send(data)
         data = s.recv(bufsize)
            # print data.strip()
         cur_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
         print ("%s receice from server :%s") % (cur_time,data)
         s.close()
    a=SMSsendx()
    a.Sms('a',18072722237)
    print time.ctime()

  • 相关阅读:
    shell编程基础干货
    HIVE的高级操作
    Linux service,挂载,定时任务等常用服务
    Linux(二)高级文本处理
    Linux基本使用命令
    07-MySQL 架构介绍
    06-Re: 视图&过程&触发器
    05-安装 MySQL5.7
    [04] 继承&聚合&war
    [03] 仓库&生命周期&插件目标
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349222.html
Copyright © 2011-2022 走看看