【第22期】观点:IT 行业加班,到底有没有价值?

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

版权声明: 举报

相关文章推荐

thrift C++做server, C++,python, java做Client例子

一、安装 我机器上已经安装好了 thrift-0.9.1 二、示例 编辑demo.thrift文件,内容如下: struct UserProfile{    ...

Spring集成Thrift--Server AND Client

Thrift网上有N多教程,不再赘述,这里搭建的是WEB项目,使用了spring,所以尽量使用了基于配置的方式。 一。server端 本着少些代码,配置优先的原则,在server端引入代理类,如下: ThriftServerProxy:使用了反射   public class ThriftSe

Python UDP Server and Client

Python UDP Server and Client最近自学python, 尝试写了些Python 的server和client Python UDP Server Python UDP Clie...

Client and Server Demo

Client and Server Demo <a href="http://www.netjava.cn/index2.php?option=com_content&amp;amp;task=view&amp;amp;id=69&amp;amp;pop=1&amp;amp;page=0&
  • kayo
  • kayo
  • 2009-03-31 13:35
  • 875

client/server程序-python

服务器: #!/usr/bin/env python # -*- coding: gbk -*- from threading import Thread #from time import ...
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

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