public Server(ProtocolConfiguration config) { if (config == null) throw new ArgumentNullException("config"); this.config = config; // PGM or UDP: if (config.UsePGM) { s = new Socket(AddressFamily.InterNetwork, SocketType.Rdm, PGM.IPPROTO_RM); } else { s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); } if (config.UseNonBlockingIO) s.UseOnlyOverlappedIO = true; s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); // Calculate send window buffer size: var sendWindow = new PGM.RMSendWindow(config.SendRateKBitsPerSec, config.SendWindowSize); if (config.UsePGM) { // PGM: s.Bind(new IPEndPoint(IPAddress.Any, config.MulticastEndpoint.Port)); // NOTE(jsd): This option fails here: //s.SetSocketOption(PGM.IPPROTO_RM, PGM.RM_SEND_WINDOW_ADV_RATE, 50); // Set the window size parameters (very important for good bandwidth utilization): s.SetSocketOption(PGM.IPPROTO_RM, PGM.RM_RATE_WINDOW_SIZE, sendWindow); } else { // Multicast UDP: s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendBuffer, (int)sendWindow.WindowSizeInBytes); if (config.UseLoopback) { s.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, 2); } } }
public Client(ProtocolConfiguration config) { if (config == null) throw new ArgumentNullException("config"); this.config = config; if (config.UsePGM) { this.s = new Socket(AddressFamily.InterNetwork, SocketType.Rdm, PGM.IPPROTO_RM); } else { this.s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); } this.s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); // Calculate send window buffer size: var sendWindow = new PGM.RMSendWindow(config.SendRateKBitsPerSec, config.SendWindowSize); this.s.ReceiveBufferSize = (int)sendWindow.WindowSizeInBytes; if (config.UseNonBlockingIO) this.s.UseOnlyOverlappedIO = true; }
internal Connection(Socket ls, CancellationToken cancel, ProtocolConfiguration config) { this.ls = ls; this.cancel = cancel; this.config = config; }