public override void StartService() { try { OnReportingStatus(StatusCode.Info, "Started configuring socket for broadcast communication"); ClientSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, true); OnReportingStatus(StatusCode.Success, "Successfully set Broadcast option"); ClientSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, 32); OnReportingStatus(StatusCode.Success, "Successfully set Multicast TTL option"); ClientSocket.Bind(new IPEndPoint(_ipAddress, _localPort)); OnReportingStatus(StatusCode.Success, $"Successfully bound to {ClientSocket.LocalEndPoint}"); if (ClientSocket.LocalEndPoint is IPEndPoint endPoint) { WhoAmI = new ClientEvent(WhoAmI.Id, endPoint, new IPEndPoint(_address, _localPort)); } Receive(); } catch (ObjectDisposedException) { } catch (SocketException socketException) { OnCaughtException(socketException, EventCode.Bind); } catch (Exception exception) { OnCaughtException(exception, EventCode.Other); } }
public void Start() { ClientSocket.Blocking = true; ClientSocket.ReceiveBufferSize = PacketServer.MTU * 5; ClientSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.PacketInformation, true); ClientSocket.Bind(ServerEndpoint); }
public override void StartService() { if (_localEndpoint is null) { Send(Array.Empty <byte>()); } else { try { ClientSocket.Bind(_localEndpoint); OnReportingStatus(StatusCode.Success, $"Successfully bound to {_localEndpoint}"); } catch (ObjectDisposedException) { } catch (SocketException socketException) { OnCaughtException(socketException, EventCode.Bind); } catch (Exception e) { OnCaughtException(e, EventCode.Other); } } }
public override void StartService() { try { ClientSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, 32); ClientSocket.Bind(new IPEndPoint(_ipAddress, _localPort)); if (ClientSocket.LocalEndPoint is IPEndPoint endPoint) { WhoAmI = new ClientEvent(WhoAmI.Id, endPoint, new IPEndPoint(_multicastAddress, _multicastPort)); } OnReportingStatus(StatusCode.Success, $"Successfully bound to {WhoAmI.Ip}:{WhoAmI.ServerIp}"); Receive(); } catch (ObjectDisposedException) { } catch (SocketException socketException) { OnCaughtException(socketException, EventCode.Bind); } catch (Exception exception) { OnCaughtException(exception, EventCode.Other); } }
public void Bind(string ipAddress, int port) { var hostPoint = new IPEndPoint(IPAddress.Parse(ipAddress), port); ClientSocket.Bind(hostPoint); }