imgeorgiev / tcpcom Goto Github PK
View Code? Open in Web Editor NEWAn event-based Python library for TCP communication between multiple devices
License: MIT License
An event-based Python library for TCP communication between multiple devices
License: MIT License
I have done some testing with these scripts and there is a problem in the server side, the MESSAGE state change is never triggered, no matter how many messages the client sends to the server, the server never acknowledges these message or execute the instructions under the MESSAGE paragraph
Hi, I am trying to combine the client and server scripts into one to create a data splitter (a script that will receive tcp/ip messages and forward those messages to two different servers). The script should be pretty simple but for some reason it is not working as expected and the data is not being received by the servers. I am thinking it might be due to a limitation of one socket open at a time or something similar, has anyone achieved something similar?
This is my code:
#!/usr/bin/python
# encoding: utf-8
from tcpcom import TCPServer, TCPClient
import time
IN_PORT = 25006
SERVER1_ADDRESS = "192.168.0.5"
SERVER1_PORT = 5006
SERVER2_ADDRESS = "192.168.0.5"
SERVER2_PORT = 5007
def onStateChangedServer(state, msg):
if state == "LISTENING":
print "Server:-- Listening...", msg
client1.disconnect()
client2.disconnect()
elif state == "CONNECTED":
print "Server:-- Connected to", msg
rc1 = client1.connect()
rc2 = client2.connect()
elif state == "MESSAGE":
print "Server:-- Message received:", msg
print "Client:-- Forward message:", msg
client1.sendMessage(msg)
client2.sendMessage(msg)
elif state == "DISCONNECTED":
print "Server:-- Disconnected", msg
def onStateChangedClient(state, msg):
if state == "CONNECTING":
print "Client:-- Connecting...", msg
elif state == "CONNECTED":
print "Client:-- Connection estabished.", msg
elif state == "DISCONNECTED":
print "Client:-- Disconnected.", msg
elif state == "MESSAGE":
print "Client:-- Received data:", msg
server = TCPServer(IN_PORT, stateChanged = onStateChangedServer)
client1 = TCPClient(SERVER1_ADDRESS, SERVER1_PORT, stateChanged = onStateChangedClient)
client2 = TCPClient(SERVER2_ADDRESS, SERVER2_PORT, stateChanged = onStateChangedClient)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.