<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[שימוש ב WebSocket | עזרה ראשונית]]></title><description><![CDATA[<p dir="rtl">שלום וברכה,<br />
מכיון שהשאלה הזו קשורה לתקשורת בין שרתים, תחום שאני די חלש בו, אשמח לעזרת והכוונת הציבור בעניין.</p>
<p dir="rtl">אני מנסה להשתמש עם WebSocket כדי לאפשר הודעות דחיפה בדפדפן (ספציפית זה לא בשביל הודעות אלא בשביל הוראה לדפדפן לרענן את הדף [אולי יש פתרונות אחרים?])</p>
<p dir="rtl">להלן הפעולות שכבר עשיתי:<br />
התקנתי rabbitQT על השרת + תוסף rabbitmq_web_stomp<br />
בקובץ /etc/rabbitmq/rabbitmq.conf  הגדרתי</p>
<pre><code>web_stomp.port = 15674
</code></pre>
<p dir="rtl">אני שולח הודעה באמצעות סקריפט פייתון</p>
<pre><code>#!/usr/bin/env python
import pika

connection = pika.BlockingConnection(
    pika.ConnectionParameters(host='localhost'))
channel = connection.channel()

channel.queue_declare(queue='hello')

channel.basic_publish(exchange='', routing_key='hello', body='Hello World!')
print(" [x] Sent 'Hello World!'")
connection.close()
</code></pre>
<p dir="rtl">ואני מקבל הודעת אישור</p>
<pre><code>[x] Sent Hello World!
</code></pre>
<p dir="rtl">בנוסף ההודעה מופיעה ברשימת ההודעה כשאני מריץ <code>rabbitmqctl list_queues</code></p>
<p dir="rtl">בנוסף יש לי קוד js</p>
<pre><code>const ws = new WebSocket("ws://161.97.125.251:15674/ws");

        ws.onopen = function () {
            console.log("WebSocket connection established.");
            ws.send(JSON.stringify({
                "type": "queue.bind",
                "queue": "hello",
                "exchange": "",
                "routing_key": "hello"
            }));
        };

        ws.onmessage = function (event) {
            console.log(event);
            const message = event.data;
            console.log("Received message:", message);  
        };
        ws.onerror = function (error) {
            console.error("WebSocket error:", error);
        };

        ws.onclose = function () {
            console.log("WebSocket connection closed.");
        };
</code></pre>
<p dir="rtl">הודעת חיבור ראשונית <code>WebSocket connection established.</code> מתקבלת,<br />
אבל אני לא מצליח לקבל את ההודעות שאני שולח מכאן והלאה</p>
<p dir="rtl">מאמין שמשהו פה בהגדרות לא מספיק מהודק,<br />
מישהו יכול לעזור לי?<br />
תודה!</p>
]]></description><link>https://tchumim.com/topic/16131/שימוש-ב-websocket-עזרה-ראשונית</link><generator>RSS for Node</generator><lastBuildDate>Sun, 15 Nov 2026 03:28:52 GMT</lastBuildDate><atom:link href="https://tchumim.com/topic/16131.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 28 Feb 2024 17:45:01 GMT</pubDate><ttl>60</ttl></channel></rss>