标签:
#! /usr/bin/python
# -*- coding: utf-8 -*-
import socket
sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
server_address = ("127.0.0.1",12345)
print "Staring up on %s:%s" % server_address
sock.bind(server_address)
sock.listen(5)
while True:
print "waiting .........."
connetion,client_address = sock.accept()
try:
print "Connection from ",client_address
data = connetion.recv(1024)
print "Receive ‘%s‘" % data
finally:
connetion.close()
#! /usr/bin/python
# -*- coding: utf-8 -*-
import socket
sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
def check_tcp_status(ip,port):
sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
server_address = (ip,port)
print "connecting to %s:%s" % server_address,port
sock.connect(server_address)
message = raw_input("pleas input: ")
print "Sending ‘%s‘" % message
sock.sendall(message)
print "Closing socket"
sock.close()
if __name__ == "__main__":
print check_tcp_status("127.0.0.1",12345)
标签:
原文地址:http://www.cnblogs.com/budongshu/p/49750e9e48b351bcb25e4aecb0cf2932.html