/
Simple TCP communications
  • Rough draft
  • Simple TCP communications

    From version 3.18 the PEKAT VISION Projects Manager can run a simple tcp server that accepts simple requests for starting or stopping projects and checking their status.

    For the details on how to start the TCP server, you can check the settings of the Projects Manager.

    This page will show how to send the requests through python script and what response type can the server send back.

    Connecting to the server

    To connect to the server, you first need to set up a socket and then connect it to the address of the TCP server. You can do it like this:

    import socket pekat_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) pekat_socket.connect(("172.22.12.67", 7002))

    In this example I am connecting to a TCP server running on an IP address 172.22.12.67 and port 7002. You can find the IP address and port number of your TCP server in the Projects Manager's settings.

    image-20241203-130205.png

    The more general code (without using specific IP adress and port) would look like this:

    import socket pekat_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) pekat_socket.connect(("<ip_address>", <port>))

    The other code segments on this page won’t be showing how to create a socket and will assume that the socket is already created.

    Requests

    The TCP server accepts 4 types of requests:

    • start request - starts a project

    • stop request - stops a project

    • status request - returns the status of a project

    • switch request - stops all projects and starts only the selected one

    All of these commands are sent to the server in the format "<command>:<project_path>", but the command must be sent as a byte stream. In code, sending the command through a socket would look like this:

    pekat_socket.send(bytes(r"<command>:<project_path>", "utf-8"))

    To then get the response from the server you can use this command:

    The response variable contains then bytes with the response from the server. You can print the response with the print()function.

    If the command you send to the server is wrong, the server will send response “Unknown command”

    If the project path you send to the server doesn’t exist or if it isn’t a PEKAT VISION project, the server will return response “not-found“. In this case, you should check the path if everything is correct and try again.

    Start Project

    To start a project, the code would look like this:

    Just replace the project path in this code with the path to the project you want to start.

    Stop Project

    To stop a project, the code would look like this:

    Again, you need to replace the path of the project in this code with the path of the project you want to stop.

    Check Project Status

    In this example, I will use python code to check the status of Test Project 1:

    Switch Project

    The switch command will turn of all projects and start the one you specified by the project path.

    Related content

    Projects Manager
    Projects Manager
    More like this
    Confusion Matrix
    Confusion Matrix
    Read with this
    PEKAT VISION SDK & API
    PEKAT VISION SDK & API
    More like this
    Preprocess
    Read with this
    REST API - Send Images to PEKAT
    REST API - Send Images to PEKAT
    More like this
    Operator View
    Operator View
    Read with this