2

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.

2
  • 1
    What transport protocol? Commented Nov 20, 2012 at 3:56
  • tcp ip, for terminal of the Operating System of windows thanks! Commented Nov 20, 2012 at 3:59

2 Answers 2

3

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)
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks you su mutch, only one thing, in the python code import time is necesary for Linux.
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.