python server and client

原创 2016年05月31日 21:33:16

python server and client

Overview:

They server is run by python3, while client is python2.7.

Server:

“python

from socket import *

ServerUrl = ":9867"

def run():
   global IP
   global PORT
   try:
       Colon = ServerUrl.find(':')
       IP = ServerUrl[0:Colon]
       Port = int(ServerUrl[Colon+1:])

   print ('Server ServerUrl %s' % ServerUrl)
   print ('Server IP:  %s' % IP)
   print ('Server Port:  %d' % Port)
   #sockobj = socket(AF_INET, SOCK_STREAM)
   sockobj = socket(AF_INET, SOCK_STREAM)
   sockobj.setsockopt(SOL_SOCKET,SO_REUSEADDR, 1)


   sockobj.bind((IP, int(Port)))

   sockobj.listen(5)
   print ('====Server here ===')

   while True:
       connection, address = sockobj.accept()

       print ('Server connected by client:%s' % str(address))
       while True:
           data = connection.recv(1024)

           if not data:
               break

           ret='200 OK'
           connection.send(ret.encode('utf-8'))
           print ('Receive MSG:%s' % data.strip())
           print ('Send ret:%s\r\n' % ret)

   connection.close( )

   except Exception as e:
       print ("The issue:%s" % e)

if __name__ == '__main__':
    run()

Client

“python

import socket

HOST = '10.86.79.59'
PORT = 9867

request = 'can you hear me?'

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))

s.sendall(request)

reply   = s.recv(1024)
print 'reply is: ',reply

s.close()

Test

Server

Client

版权声明:

相关文章推荐

Simple HTTP Server and Client in Python

This time I'd like to show you how to make a simple HTTP server and client in python. It's a bit dif...

Thrift tutorial(python server and php client)

定义IDL文件hello.thrift struct User { 1: string firstname 2: string lastname } exception UserExcep...

001 ZeroMQ server and client

研究了一下,这个库神奇而优秀,自己理解定义为:高效、简炼、TCP/IP层以上网络的、进程间的、线程间的消息队列(Message Queue)。 官网:http://zeromq.org/ RFC:...

libevent for echo server and client

echo server: #include #include #include #include #include #include #include #include #def...

twisted-01 Echo server and echo client

twisted的几个核心组件protocol,transport,factory,defer,reactor,把这几个关键组件搞清楚了,也就算是twisted入门了,大致关系是这样的由reactor来...

Web.js MVC between client and server

转载于:http://cnodejs.org/topic/4f16442ccae1f4aa270010c3     Web.js 是一个 为简化 HTTP 开发而设计的 Web Framewor...

Simple UDP server and client

server: ////////////////////////////////////////////////////////// // UDPServer.cpp文件 #include ...

Ubuntu VPN (PPTP\L2TP\OpenVPN) server and client

PPTP L2TP OpenVPN

Understanding the differences between client/server and peer-to-peer networks

If you work with computers long enough, sooner or later you’ll hear the terms “client/server” and “p...

How to setup linked servers for SQL Server and Oracle 64 bit client

How to setup linked servers for SQL Server and Oracle 64 bit client ProblemWe have two SQL 2005 64-b...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)