Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage of RaSTA/gRPC bridge with Python #81

Open
spadetsky opened this issue Mar 7, 2024 · 1 comment
Open

Usage of RaSTA/gRPC bridge with Python #81

spadetsky opened this issue Mar 7, 2024 · 1 comment

Comments

@spadetsky
Copy link

Hi everyone,

I'm encountering an issue while trying to integrate the Rasta bridge into my Python code. Here's what I've observed:

Problem:
I have a Python server and client code that communicates successfully directly, using the rasta_pb2
and rasta_pb2_grpc generated by this .proto file provided in the repository.
However, when I attempt to use the Rasta bridge, the communication doesn't seem to work as expected.
I used the Getting started guide to setup everything
First of all, after the build i tested the rcat_tcp executable to verify if the build is working
Then i implemented server.py and client.py code and tested if its work directly
Server.py:

import grpc
import time
import concurrent.futures as futures
import rasta_pb2
import rasta_pb2_grpc

class RastaServicer(rasta_pb2_grpc.RastaServicer):
    def Stream(self, request_iterator, context):
        for req in request_iterator:
            # Echo the received message back to the client
            yield rasta_pb2.SciPacket(message=req.message)

def serve():
    server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
    rasta_pb2_grpc.add_RastaServicer_to_server(RastaServicer(), server)
    server.add_insecure_port('[::]:50051')
    server.start()
    print("Server started. Listening on port 50051...")
    try:
        while True:
            time.sleep(86400)
    except KeyboardInterrupt:
        server.stop(0)

if __name__ == '__main__':
    serve()

Client.py:

import grpc
import rasta_pb2
import rasta_pb2_grpc

def run():
    with grpc.insecure_channel('localhost:50051') as channel:
        stub = rasta_pb2_grpc.RastaStub(channel)
        print("Enter your messages (press Ctrl+D to finish):")
        while True:
            try:
                message = input("Your message: ")
                response = stub.Stream(iter([rasta_pb2.SciPacket(message=message.encode())]))
                for resp in response:
                    print("Received:", resp.message.decode())
            except EOFError:
                print("Client finished sending messages.")
                break

if __name__ == '__main__':
    run()

After the successful test i prepared these commands with these instructions to run the bridges:
For the server:

./rasta_grpc_bridge_tcp rasta_server_local.cfg localhost:50051 127.0.0.1:8888 127.0.0.1:8889 127.0.0.1:9998 127.0.0.1:9999 1234 5678

and the terminal output:

Server listening on localhost:50051

For the client:

./rasta_grpc_bridge_tcp rasta_client_local.cfg localhost:50051 127.0.0.1 8888 127.0.0.1 8889 1233 5678 localhost:50052 

and the terminal output:

[03/07/24|12:17:01 (Epoch time: 1709810221386)][DEBUG][RaSTA HANDLE_INIT] Loaded accepted version: 0303

I changed in the client.py code the port to 50052 and ran the program, after sending the text i receive this error from the client.py:

spadetsky@Pavlos-MBP Documents % python3 rastatest_client.py
Enter your messages (press Ctrl+D to finish):
Your message: 123
Traceback (most recent call last):
  File "/Users/spadetsky/Documents/rastatest_client.py", line 20, in <module>
    run()
  File "/Users/spadetsky/Documents/rastatest_client.py", line 13, in run
    for resp in response:
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/grpc/_channel.py", line 542, in __next__
    return self._next()
           ^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/grpc/_channel.py", line 968, in _next
    raise self
grpc._channel._MultiThreadedRendezvous: <_MultiThreadedRendezvous of RPC that terminated with:
	status = StatusCode.UNAVAILABLE
	details = "failed to connect to all addresses; last error: UNKNOWN: ipv4:127.0.0.1:50052: Failed to connect to remote host: Connection refused"
	debug_error_string = "UNKNOWN:Error received from peer  {created_time:"2024-03-07T12:19:39.726899+01:00", grpc_status:14, grpc_message:"failed to connect to all addresses; last error: UNKNOWN: ipv4:127.0.0.1:50052: Failed to connect to remote host: Connection refused"}"

And after some time, the terminal with client bridge outputs this:

The socket could not be initialized: Too many open files
zsh: abort      ./rasta_grpc_bridge_tcp rasta_client_local.cfg localhost:50051 127.0.0.1 8888

The .cfg files I used are the same as the ones i used for the rcat_tcp and I did not make any changes to them, they are the same as the .cfg files in the repository

I suspect that there might be something missing or incorrect in the way I'm running the Rasta bridge.
Could someone provide guidance on how to correctly set up and use the Rasta bridge with Python code?
Apologies if this is a basic question; I'm still learning and want to ensure I'm not missing any crucial steps.

@laugengebaeck
Copy link
Collaborator

Probably your system limits the number of open file descriptors too much, so the Rasta bridge cannot open a socket (which is likely if you have lots of other processes running). Please check with ulimit -n and, if it's smaller than 1024, increase by running ulimit -n 1024.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants