简体   繁体   中英

Python Socket Programming

I am developing a testbed for cloud computing environment. I want to establish multiple client connection to a server. What I want is that, server first of all send a data to all the clients specifying sending_interval and then all the clients will keep on sending their data with a time gap of that time_interval (as specified by the server). Please help me out, how can I do the same using python socket program. (ie I want multiple client to single server connectivity and also client sending data with the time gap specified by server). Will be great-full if anyone can help me. Thanks in advance.

This problem is easily solved by the ZeroMQ socket library . It is production stable. It allows you to define publisher-subscriber relationships, where a publishing process will publish data on a port regardless of how many (0 to infinite) listening processes there are. They call this the PUB-SUB model; it's in their docs (link below).

It sounds like you want to set up a bunch of clients that are all publishers. They can subscribe to a controlling channel, which which will send updates to their configuration (how often to write). They also act as publishers, pushing out their own data at an interval specified by default/config channel/socket.

Then, you have one or more listening processes that listen to all the clients' published messages. Perhaps you could even have two listening processes, one for backup or DR, or whatever.

We're using ZeroMQ and loving the simplicity it gives ; there's no connection errors because the publisher doesn't care if anyone is listening, and the subscriber can start before the publisher and if there's nothing there to listen to, it can just loop around and wait until there is.

Bindings are available in ALL languages (it's freaky). The Python binding isn't pure-python, it does require a C compiler, but is frighteningly fast, and the pub/sub example is a cut/paste, 'golly, it works!' experience.

Link: http://zeromq.org

There are MANY other methods available with this library, including message queues, etc. They have relatively complete documentation, too.

Multi-Client and Single server Socket programming can be achieved by Multithreading in Socket Programming. I have implemented both the method:

  1. Single Client and Single Server
  2. Multiclient and Single Server

In my GitHub Repo Link: https://github.com/shauryauppal/Socket-Programming-Python

What is Multi-threading Socket Programming? Multithreading is a process of executing multiple threads simultaneously in a single process.

To understand well you can visit Link: https://www.geeksforgeeks.org/socket-programming-multi-threading-python/ , written by me.

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