亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

python怎么使用socket先讀取長度,在讀取報文內容

發布時間:2021-03-30 09:41:04 來源:億速云 閱讀:594 作者:小新 欄目:開發技術

這篇文章主要介紹了python怎么使用socket先讀取長度,在讀取報文內容,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

本文實例講述了python使用socket 先讀取長度,在讀取報文內容。分享給大家供大家參考,具體如下:

tlpmts1:~/sbin # cat test9105.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):
   #.decode('utf-8').encode('gbk')
   host='10.4.160.71'
   port = 9105
   print 'host'+'->'+host
   print 'port'+'->'+str(port)
   bufsize=10240
   addr=(host,port)
   s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
   s.settimeout(20)
   s.connect((host,port))
   data=''
   # data='<?xml version="1.0" encoding="UTF-8"?><SERVICE><SYS_HEAD><USER_ID>007144</USER_ID><TRAN_TIMESTAMP>100443923</TRAN_TIMESTAMP><AUTH_USER_ID_ARRAY><AUTH_CHECK_FLAG></AUTH_CHECK_FLAG><AUTH_CHECK_MSG></AUTH_CHECK_MSG><AUTH_USER_ID></AUTH_USER_ID></AUTH_USER_ID_ARRAY><BRANCH_ID>330600600</BRANCH_ID><TRAN_DATE>20170920</TRAN_DATE><ORG_SYS_ID>101020</ORG_SYS_ID><SOURCE_TYPE>A01</SOURCE_TYPE><PROVIDER_ID>301020</PROVIDER_ID><CONSUMER_SEQ_NO>10102020170926010000550744</CONSUMER_SEQ_NO><WS_ID>10.4.129.21</WS_ID><SERVICE_SCENE>17</SERVICE_SCENE><SERVICE_CODE>01003000003</SERVICE_CODE><CONSUMER_ID>101020</CONSUMER_ID><FILE_PATH></FILE_PATH></SYS_HEAD><APP_HEAD><LKG_FLAG></LKG_FLAG><CURRENT_NUM>0</CURRENT_NUM><WNDW_NO>0</WNDW_NO><REVERSAL_DATE></REVERSAL_DATE><TOTAL_ROWS></TOTAL_ROWS><PSWD_KEY_INDX></PSWD_KEY_INDX><SEND_TRAN_CODE></SEND_TRAN_CODE><PSWD_ECPTN_FLG></PSWD_ECPTN_FLG><AHR_MODE></AHR_MODE><BUSS_SEQ_NO>10102020170926010000550744</BUSS_SEQ_NO><WARN_CFM_FLAG></WARN_CFM_FLAG><CORP_CODE>9999</CORP_CODE><TOTAL_NUM>14</TOTAL_NUM><FEE_CFM_FLAG></FEE_CFM_FLAG><LKG_TRAN_CODE></LKG_TRAN_CODE><SEND_TRAN_NAME></SEND_TRAN_NAME><TRAN_SCENE>0000000000</TRAN_SCENE><PGUP_OR_PGDN></PGUP_OR_PGDN><CHNL_FLG_STRG>10000000000000000000</CHNL_FLG_STRG><REVERSAL_SEQ_NO></REVERSAL_SEQ_NO><REVERSAL_TRAN_TYPE></REVERSAL_TRAN_TYPE></APP_HEAD><LOCAL_HEAD></LOCAL_HEAD><BODY><CURRENT_NUM>0</CURRENT_NUM><ACCT_NO>33010000201000000459</ACCT_NO><PASSWORD_TYPE>0</PASSWORD_TYPE><START_PAGE>1</START_PAGE><TOTAL_NUM>14</TOTAL_NUM><ACCT_SERIAL_NO></ACCT_SERIAL_NO><RET_CERT_SBU_ACCT_DETAIL_FLG>1</RET_CERT_SBU_ACCT_DETAIL_FLG><SVC_FIELD>0110111100</SVC_FIELD></BODY></SERVICE>'
   # length = len(data.encode('utf-8'))
   # slen = '%08d' % length
   # data=slen + data
   # data='000314<?xml version="1.0" encoding="UTF-8"?> <Esb> <head> <Serial>21801020180528010000218475</Serial> <Channel>L06</Channel> <DateTime>2018052810241220</DateTime> <HostCode>ES999</HostCode> <TermNo>APP</TermNo> <TxnUsr>ZXGY</TxnUsr> <TxnOrg>999999999</TxnOrg> <CONSUMER_ID>218010</CONSUMER_ID> </head> </Esb>'
   data='<?xml version="1.0" encoding="UTF-8"?> <SERVICE> <SYS_HEAD> <USER_ID>004355</USER_ID> <TRAN_TIMESTAMP>173906133</TRAN_TIMESTAMP> <BRANCH_ID>330100921</BRANCH_ID> <BACK_TXN_CD>ES999</BACK_TXN_CD> <CORP_CODE>9999</CORP_CODE> <TRAN_DATE>20190528</TRAN_DATE> <ORG_SYS_ID>202020</ORG_SYS_ID> <SOURCE_TYPE>M01</SOURCE_TYPE> <ESB_SEQ_NO>50010120190528010000002780</ESB_SEQ_NO> <PROVIDER_ID>201010</PROVIDER_ID> <VERSION></VERSION> <CONSUMER_SEQ_NO>20202020190528878173906123</CONSUMER_SEQ_NO> <MESSAGE_CODE>0001</MESSAGE_CODE> <SERVICE_SCENE>27</SERVICE_SCENE> <CONSUMER_ID>202020</CONSUMER_ID> <SERVICE_CODE>01003000003</SERVICE_CODE> </SYS_HEAD> <APP_HEAD> <BUSS_SEQ_NO>20202020190424878173906123</BUSS_SEQ_NO> </APP_HEAD> <LOCAL_HEAD></LOCAL_HEAD> </SERVICE>'
   length = len(data.encode('utf-8'))
   slen = '%08d' % length
   data=slen + data
   print data
   recv_size = 0
   #msg = data.encode('gbk')
   s.send(data)
   data = s.recv(bufsize)
   # print data.strip()
   length=data
   print int(length)
   resp = s.recv(int(length));
   cur_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
   print ("%s receice from server :%s") % (cur_time,data + resp)
a=SMSsendx()
a.Sms()
print time.ctime()

tlpmts1:~/sbin # python test9105.py
Thu Jul  4 16:06:43 2019
host->10.4.160.71
port->9105
00000754<?xml version="1.0" encoding="UTF-8"?> <SERVICE> <SYS_HEAD> <USER_ID>004355</USER_ID> <TRAN_TIMESTAMP>173906133</TRAN_TIMESTAMP> <BRANCH_ID>330100921</BRANCH_ID> <BACK_TXN_CD>ES999</BACK_TXN_CD> <CORP_CODE>9999</CORP_CODE> <TRAN_DATE>20190528</TRAN_DATE> <ORG_SYS_ID>202020</ORG_SYS_ID> <SOURCE_TYPE>M01</SOURCE_TYPE> <ESB_SEQ_NO>50010120190528010000002780</ESB_SEQ_NO> <PROVIDER_ID>201010</PROVIDER_ID> <VERSION></VERSION> <CONSUMER_SEQ_NO>20202020190528878173906123</CONSUMER_SEQ_NO> <MESSAGE_CODE>0001</MESSAGE_CODE> <SERVICE_SCENE>27</SERVICE_SCENE> <CONSUMER_ID>202020</CONSUMER_ID> <SERVICE_CODE>01003000003</SERVICE_CODE> </SYS_HEAD> <APP_HEAD> <BUSS_SEQ_NO>20202020190424878173906123</BUSS_SEQ_NO> </APP_HEAD> <LOCAL_HEAD></LOCAL_HEAD> </SERVICE>
539
2019-07-04 16:06:43 receice from server :00000539<?xml version="1.0" encoding="UTF-8"?><SERVICE><SYS_HEAD><RET><RET_CODE>0000</RET_CODE>
<RET_MSG>交易成功</RET_MSG>
</RET><TRAN_DATE>20190528</TRAN_DATE>
<TRAN_TIMESTAMP>173906133</TRAN_TIMESTAMP>
<SERVICE_CODE>01003000003</SERVICE_CODE>
<SERVICE_SCENE>27</SERVICE_SCENE>
<CONSUMER_SEQ_NO>20202020190528878173906123</CONSUMER_SEQ_NO>
<PROVIDER_ID>201010</PROVIDER_ID>
<CONSUMER_ID>202020</CONSUMER_ID>
</SYS_HEAD><APP_HEAD><BUSS_SEQ_NO>20202020190424878173906123</BUSS_SEQ_NO>
<TOTAL_NUM></TOTAL_NUM>
</APP_HEAD><BODY></BODY></SERVICE>
Thu Jul  4 16:06:43 2019

感謝你能夠認真閱讀完這篇文章,希望小編分享的“python怎么使用socket先讀取長度,在讀取報文內容”這篇文章對大家有幫助,同時也希望大家多多支持億速云,關注億速云行業資訊頻道,更多相關知識等著你來學習!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

平乡县| 新源县| 邹城市| 略阳县| 闽清县| 湟中县| 青海省| 贵南县| 鲁山县| 彩票| 泸州市| 鄱阳县| 韩城市| 东山县| 井研县| 龙海市| 美姑县| 都安| 汤原县| 奉化市| 驻马店市| 息烽县| 师宗县| 北流市| 荆州市| 古田县| 瑞昌市| 兴隆县| 沙河市| 千阳县| 河源市| 辽中县| 南华县| 九江市| 巴青县| 宝应县| 叙永县| 博客| 湖口县| 营山县| 昌黎县|