Errno 111 connection refused

I’m trying to write a program that transfers realtime video from seek thermal integrated with raspberry pi 3b+, flask server with websocket protocol and PC, where the raspberry pi acts as a client that captures and streams the realtime frames to the flask server, and the pc acts as a server that receive frames and apply people detection using yolov8 AI model to them before displaying them, but unfortunately when i try to run the code on both raspberry pi and pc i get connection refused, can someone help me please?

**the client code: **

import cv2
import numpy as np
from threading import Condition
import websocket
from seekcamera import (
    SeekCameraIOType,
    SeekCameraColorPalette,
    SeekCameraManager,
    SeekCameraManagerEvent,
    SeekCameraFrameFormat,
    SeekCamera,
    SeekFrame,
)

class Renderer:
    def _init_(self):
        self.busy = False
        self.frame = SeekFrame()
        self.camera = SeekCamera()
        self.frame_condition = Condition()
        self.first_frame = True

def on_frame(_camera, camera_frame, renderer):
    with renderer.frame_condition:
        renderer.frame = camera_frame.color_argb8888
        renderer.frame_condition.notify()

def on_event(camera, event_type, event_status, renderer):
    print("{}: {}".format(str(event_type), camera.chipid))

    if event_type == SeekCameraManagerEvent.CONNECT:
        if renderer.busy:
            return

        renderer.busy = True
        renderer.camera = camera

        renderer.first_frame = True

        camera.color_palette = SeekCameraColorPalette.WHITE_HOT

        camera.register_frame_available_callback(on_frame, renderer)
        camera.capture_session_start(SeekCameraFrameFormat.COLOR_ARGB8888)

    elif event_type == SeekCameraManagerEvent.DISCONNECT:
        if renderer.camera == camera:
            camera.capture_session_stop()
            renderer.camera = None
            renderer.frame = None
            renderer.busy = False

    elif event_type == SeekCameraManagerEvent.ERROR:
        print("{}: {}".format(str(event_status), camera.chipid))

def stream_video(renderer):
    ws = websocket.create_connection("ws://127.0.0.1:8080/stream")
    while True:
        with renderer.frame_condition:
            renderer.frame_condition.wait(150.0 / 1000.0)
            frame = renderer.frame
            ws.send_binary(frame)
    ws.close()

if _name_ == "_main_":
    renderer = Renderer()
    with SeekCameraManager(SeekCameraIOType.USB) as manager:
        manager.register_event_callback(on_event, renderer)

        # Stream video to Flask server
        stream_video(renderer)

**the server code: **

from flask import Flask
import cv2
import numpy as np
from ultralytics import YOLO
import supervision as sv
#code for people detection on pc
app = Flask(name)

model = YOLO('yolov8n.pt')

@app.route('/stream')
def stream():
    return 'Streaming...'

def processframe(frame):
    while True:
    # Convert frame to OpenCV format
        frame = cv2.imdecode(np.frombuffer(frame, np.uint8), cv2.IMREADCOLOR)

    # Perform people detection using YOLOv8
        results = model(frame)[0]
        detections = sv.Detections.fromultralytics(results)

    # Annotate the frame
        labelannotator = sv.LabelAnnotator(
            border_radius=1,
            text_thickness=2,
            text_scale=1
         )
        annotated_frame = label_annotator.annotate(scene=frame, detections=detections)

    # Display the annotated frame
        cv2.imshow('Seek Thermal Camera', annotated_frame)
        cv2.waitKey(1)

if _name == "_main":
    import websocket

    ws = websocket.WebSocketApp("ws://192.168.1.8:8080/stream",
                                on_message=lambda ws, message: print(f"Received message: {message}"),
                                on_error=lambda ws, error: print(f"Error: {error}"),
                                on_close=lambda ws, close_status_code, close_reason: print(f"Connection closed: {close_status_code} - {close_reason}"))

    ws.run_forever()

I tried those codes as a client and server, and this error occurs “Errno 111 connection refused”.

New contributor

Nancy Mohammed is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật