GithubHelp home page GithubHelp logo

Comments (4)

skv02 avatar skv02 commented on June 8, 2024

Here is my client file. i need a small suggestion if my client is implemented good regarding with_tcp_transport() function.

from logging import addLevelName
import string
import random
from random import randint
from iec62056_21.client import Iec6205621Client

HOST = '127.0.0.1'

PORT = 8081

address = (HOST, PORT)

def int_generator(chars=range(0, 250000)):
"""Function to generate random integers with with specified size"""
return random.choice(chars)

#-----------------------------------------------------------------------#

Initialize Iec6205621Client instance with tcp

#-----------------------------------------------------------------------#
def Run_client():

 client = Iec6205621Client.with_tcp_transport(address=(HOST, PORT))

 print("socket created")
 
 client.connect()
 
 print("connected with server successfully")

 number_of_data_to_send = 100

 sent_data = 0
 while(sent_data < number_of_data_to_send):
     data = int_generator()
     client.write_single_value(address=address, data=data)
     sent_data+=1

 client.disconnect()
 
 print("client disconnected")

if name == "main":
Run_client()

from iec62056-21.

Krolken avatar Krolken commented on June 8, 2024

Hi.

You are getting a ConnectionRefusedError on the TCP connection. There is no service to receive your connection. If you are running them as docker containers I would assume that you have to reference the other containers IP or hostname, not the loopback interface 127.0.0.1

from iec62056-21.

skv02 avatar skv02 commented on June 8, 2024

Here is my server file. as you mentioned , my server here is accepting the service connection from client side. Can you provide some more idea, As you said there is no service to recieve my connection.

HOST = '127.0.0.1' # Standard loopback interface address (localhost)

PORT = 8081 # Port to listen on (non-privileged ports are > 1023)

address = (HOST, PORT)

recieved_data = []

ack = "\x06"

byte_ack = bytes(ack, 'utf-8')

#---------------------------------------------------------------------#
#initialising server to accept client connection
#---------------------------------------------------------------------#

def run_server():

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as server:
  
     print("socket created")

     server.bind((HOST, PORT))
     server.listen()

     print("waiting for connections")

     print ('Listening on .... ', (HOST, PORT))

     conn, address = server.accept()

     with conn:
         print('Successfully connected with', address)
         while True:
             data = conn.recv(1024)
             # Stop loop if no more data is received
             if not data:
                 break
             recieved_data.append(data)
             # Sending an ack in bytes to meter
             conn.sendall(byte_ack)

         print(recieved_data)
 
server.close()
print("server diconnected")

if name == "main":
run_server()

from iec62056-21.

Krolken avatar Krolken commented on June 8, 2024

If you are using docker you cannot use the loopback interface to bind the service on as this is not available outside of the container. You also need to set up correct port exposing for the container.

I'm gonna close this issue since it is related to docker and/or networking and not this library.

from iec62056-21.

Related Issues (20)

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.