Websockets in Python

แชร์
ฝัง
  • เผยแพร่เมื่อ 22 ธ.ค. 2024

ความคิดเห็น • 28

  • @cheybrown2076
    @cheybrown2076 6 วันที่ผ่านมา

    Wow! Can’t believe this content is free. I’ve been trying to build an NHS Consultation Assistant but I’m struggling to debug my code and so I’ve decided to take a step back and fully understand websockets. Thank you so much for this and the free course on your website!

  • @abdullahyousef3596
    @abdullahyousef3596 11 หลายเดือนก่อน +3

    Thank you for this video, it was really helpful!

  • @mcmouse92
    @mcmouse92 ปีที่แล้ว +2

    Very helpful info! Thank you

  • @IsraelAlfaro
    @IsraelAlfaro 9 หลายเดือนก่อน +2

    Thanks so much for this video! It was very helpful. I am now wondering, how could you introduce authentication in order to connect to the websocket server? e.g. as you would with a Bearer Token when using RESTful APIs. Thanks a gain! Cheers!

    • @apm
      @apm  9 หลายเดือนก่อน +4

      To introduce authentication to a WebSocket server, you have several options: authenticate during the initial WebSocket handshake by including a token in the URL or a custom HTTP header, authenticate immediately after the connection using the first message from the client, leverage existing session IDs, or use tokens from OAuth or external providers. Use WebSocket Secure (WSS) with TLS/SSL to ensure the security of the authentication tokens and data transmitted. The choice of method depends on your application requirements and architecture, and you should also consider the management of token expiration and renewal due to the long-lived nature of WebSocket connections.

    • @IsraelAlfaro
      @IsraelAlfaro 9 หลายเดือนก่อน +1

      @@apm thanks so much! Would you mind recommending another video/tutorial/post I could use as a reference, to follow along? Thanks once more!

    • @apm
      @apm  9 หลายเดือนก่อน +1

      @@IsraelAlfaro more information is on the Data-Driven Engineering course website, freely available at apmonitor.com/dde

  • @Hallucinarix
    @Hallucinarix 6 หลายเดือนก่อน +1

    is there a reason you nest the uri within a function rather than being declared outside as a variable that can easier be visually identified when needing to be changed? (say going from dev to production)

    • @apm
      @apm  6 หลายเดือนก่อน +2

      Great idea - it just adds an additional input parameter to the function, but makes the code more modular and reusable for other applications.

  • @georgigeorgiev3970
    @georgigeorgiev3970 5 หลายเดือนก่อน +1

    This works fine. But each client has its own socket with the server. Is there a way to make it like all clients see the changes other client does on server?
    For example having them connected to the same socket, or server sends info via each socket once DB changes?

    • @apm
      @apm  5 หลายเดือนก่อน

      MQTT has a broker that serves as a database: apmonitor.com/dde/index.php/Main/MQTTProtocol MQTT is often used for devices that are intermittently connected and where fault tolerance is needed.
      OPC UA has server where values are stored: apmonitor.com/dde/index.php/Main/OPCTransfer OPC is used in industrial automation.
      Modbus has a server / client function: apmonitor.com/dde/index.php/Main/ModbusTransfer It is an older standard that is fast and reliable.

  • @Anorch-oy9jk
    @Anorch-oy9jk 8 หลายเดือนก่อน

    if my server also has to handle api calls, how can I combine that? I know how to asnyc it, but my issue is the server IP. Locally I use fast api and a ws endpoint. But once deployed with https protocol, the ws endpoint no longer works

    • @apm
      @apm  7 หลายเดือนก่อน +1

      You need to switch to wss instead of ws for https protocol.

    • @Anorch-oy9jk
      @Anorch-oy9jk 7 หลายเดือนก่อน +1

      @@apm managed to do it! The clients needed to do a handshake cause the server was secured hosted as https and so the ws endpoint also switched to secured wss.

  • @UncleDavid
    @UncleDavid ปีที่แล้ว +3

    can you make a tutoriel-if possible-on sending HTML over websocket without js

    • @DuneKraftwerk
      @DuneKraftwerk ปีที่แล้ว +2

      Websocket is a library, you need a program to load this library, like js for instance and then sending a html strings will be possible

  • @chenbruce318
    @chenbruce318 7 หลายเดือนก่อน +2

    thanks for such comprehensive sharing!!
    I have one question, are there any suggested solutions that allow me to deploy my websocket server to let external devices access it through link like wss:// ?

    • @rrc
      @rrc 7 หลายเดือนก่อน +2

      Yes, no problem on deploying it as a web service. Just open the firewall on port 443 to not block the connection.

  • @alaaosama7679
    @alaaosama7679 5 หลายเดือนก่อน

    I know it’s a stupid question but aren’t websockets requiring internet to work?

    • @apm
      @apm  5 หลายเดือนก่อน +2

      @@alaaosama7679 websockets communicate over TCP/IP. WebSockets in Python do not inherently require the Internet to work. WebSockets are designed to establish a full-duplex communication channel over a single TCP connection, which can be used on local networks as well as over the Internet. Whether they need the Internet depends on the specific application and the endpoints involved in the communication. If both the WebSocket client and server are on the same local network or even the same machine, the Internet is not required.

  • @prasaddissanayake1718
    @prasaddissanayake1718 ปีที่แล้ว +2

    excellent

  • @AnamitraDey-v9w
    @AnamitraDey-v9w 2 หลายเดือนก่อน

    all this could be. done with just an http server, dont think the websocket usecase was truly explored

  • @chainsawman-stoic
    @chainsawman-stoic ปีที่แล้ว +3

    bro why u speaking in 0.25

    • @apm
      @apm  ปีที่แล้ว +17

      Yes, I'm speaking slowly. Fortunately, TH-cam allows you to increase speed up to 2x :)

    • @upsenloyn
      @upsenloyn 9 หลายเดือนก่อน

      ​@@apmgood one

  • @Hallucinarix
    @Hallucinarix 6 หลายเดือนก่อน +1

    is there a reason you nested the uri within the function rather than an outside variable that's easier to visually identify? (say when needing to change when going from dev to production)