python -socket -client
生活随笔
收集整理的這篇文章主要介紹了
python -socket -client
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
socket client 發(fā)起連接。
流程為:
創(chuàng)建接口
發(fā)起連接
?
創(chuàng)建接口參數(shù)同socket server相同
發(fā)起連接的函數(shù)為socket.connect(ip,port)
這個地方的ip與port為socket server端的ip和監(jiān)聽port。
代碼示例:
# -*- coding: utf-8 -*-
'''
This is a testing program
the program is used to test socket client
'''
import socket
import sysdef start_tcp_client(ip, port):#server port and ipserver_ip = ipservr_port = porttcp_client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)try:tcp_client.connect((server_ip, server_port))except socket.error:print 'fail to setup socket connection'tcp_client.close()
?
轉(zhuǎn)載于:https://www.cnblogs.com/felixwa/p/6039245.html
總結(jié)
以上是生活随笔為你收集整理的python -socket -client的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 红色1元纸币值多少钱?
- 下一篇: 作业六