עבור לתוכן
View in the app

A better way to browse. Learn more.

HWzone

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

C# Multicasting - Send & Recieve

Featured Replies

פורסם

**הסבר קצרצר על הקוד: אני פותח "קבוצה" ושניה לפני השורה שבה אני מחכה לנתונים אני שולח נתונים על ידי יצירת thread שמביא אותי לפעולה ששולחת נתונים**

הקוד פועל מעולה אבל אני לא הבנתי למה בSEND לא רשום השורה הבאה גם:


server.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, MulticastOption);

ומה ההבדל בין ליצור את הקבוצה ולהגדיר את הסוקט להיות חלק ממנה (השורה למעלה^) לבין לעשות : JoinMulticastGroup


using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
class MAIN
{
private static MulticastOption CreateGroup()
{
return new MulticastOption(IPAddress.Parse("224.100.0.1"));
}
private static void Receive(MulticastOption MulticastOption)
{
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
IPEndPoint iep = new IPEndPoint(IPAddress.Any, 9050);
EndPoint ep = (EndPoint)iep;
sock.Bind(iep);
sock.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, MulticastOption);
//
byte[] data = new byte[1024];
new Thread(new ThreadStart(Send)).Start();
int recv = sock.ReceiveFrom(data, ref ep);
string stringData = Encoding.ASCII.GetString(data, 0, recv);
Console.WriteLine("received: {0} from: {1}", stringData, ep.ToString());
sock.Close();
}
private static void Send()
{
Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
IPEndPoint iep = new IPEndPoint(IPAddress.Parse("224.100.0.1"), 9050);


byte[] data = Encoding.ASCII.GetBytes("This is a test message");
server.SendTo(data, iep);
server.Close();
}
public static void Main(String[] args)
{
Receive(CreateGroup());
Console.ReadKey();
}
}

אם זה משנה, הקוד הוא מפה: http://codeidol.com/csharp/csharp-network/IP-Multicasting/Csharp-IP-Multicast-Support/

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.