简体   繁体   中英

Example for a simple Python client and C++ server

Hello -- I need a simple example to help me understand how to write a Python client and C++ server. Can someone help me find an example of how to send hello world from a server running C++ to Python client? I tried searching Google and other websites for several hours and couldn't find a single example on how to send a parameter through tcp/ip.

Have a look at this http://www.cs.utah.edu/~swalton/listings/sockets/programs/part2/chap6/simple-server.c , It is a simple echo server that accepts connections on port 9999 and echos received message.

For python side this is not very hard, look at this example:

import socket, time

client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(('localhost', 9999))
print client.send('Hello world!'), 'bytes sent.'
time.sleep(0.2)
print 'Received message:', client.recv(1024)

use zeromq lib.. . c++ example of 'hello_world' for server and client are at :

http://zguide.zeromq.org/cpp:hwserver , http://zguide.zeromq.org/cpp:hwclient
respectively.. .

and in python.. . study the examples available at github.. . https://github.com/zeromq/pyzmq/tree/master/examples

Well for my own purpose i am using python for both end.. .Also for more tutorial watch this pycon video
http://blip.tv/pycon-us-videos-2009-2010-2011/pycon-2011-advanced-network-architectures-with-zeromq-4896861 also there is another nice tutorial at http://blog.pythonisito.com/2012/08/distributed-systems-with-zeromq.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM