GithubHelp home page GithubHelp logo

tcpcom's People

Contributors

imgeorgiev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

sheimy

tcpcom's Issues

Message receive doesn´t trigger the MESSAGE state change

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

Help to create a data splitter

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.