public override void Init(OpenAccessClusterMsgHandler messageHandler, string serverName, string identifier, IOpenAccessClusterTransportLog log) { this.handler = messageHandler; this.log = log; if (string.IsNullOrWhiteSpace(this.multicastAddress) || this.multicastPort <= 0) { throw new ArgumentException("Missing MulticastAddress setting."); } IPAddress ip = IPAddress.Parse(multicastAddress); IPEndPoint ipep = new IPEndPoint(ip, multicastPort); // create send socket senderSocket = new Socket(AddressFamily.InterNetwork, SocketType.Rdm, (ProtocolType)113); // bind socket to network interface IP address ANY //sendSocket.Bind(new IPEndPoint(IPAddress.Any, 0)); // connect socket to multicast address group senderSocket.Connect(ipep); receiverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Rdm, (ProtocolType)113); // bind socket to multicast group receiverSocket.ExclusiveAddressUse = false; receiverSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); receiverSocket.Bind(ipep); receiverSocket.Listen(10); receiverSocket.BeginAccept(OnAccept, null); }
public override void Init(OpenAccessClusterMsgHandler messageHandler, string serverName, string identifier, IOpenAccessClusterTransportLog log) { this.handler = messageHandler; this.log = log; if (string.IsNullOrWhiteSpace(this.multicastAddress) || this.multicastPort <= 0) { throw new ArgumentException("Missing MulticastAddress setting."); } IPAddress ip; if (IPAddress.TryParse(this.multicastAddress, out ip) == false) { throw new ArgumentException(string.Format("Unable to parse IP address {0}", this.multicastAddress)); } IPEndPoint ipep = new IPEndPoint(ip, multicastPort); // Create a TCP/IP socket. socket = new Socket(ip.AddressFamily, SocketType.Stream, ProtocolType.Tcp); try { socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, 1); // Connect the socket to the remote endpoint socket.Connect(ipep); var greeting = Encoding.UTF8.GetBytes(string.IsNullOrEmpty(this.Localpath) ? "<Localpath>" : this.Localpath); SendBase(greeting, socket, OpCode.Hello); byte[] tmp = new byte[HeaderLength]; if (ReceiveAll(socket, tmp, 0, tmp.Length)) { OpCode code; if (ReadHeader(tmp, out code) == 0 && (code & OpCode.Welcome) != 0) { receiverThread = new Thread(new ThreadStart(ReceiveLoop)); receiverThread.Name = "Cache Eviction Listener for " + ipep.ToString(); receiverThread.Start(); } else { Close(); } } else { Close(); } } catch { Close(); throw; } if (socket == null) { throw new InvalidOperationException("Initial Handshake with TcpCacheClusterServer failed."); } }
public override void Init(OpenAccessClusterMsgHandler messageHandler, string serverName, string identifier, IOpenAccessClusterTransportLog log) { this.handler = messageHandler; this.log = log; if (string.IsNullOrWhiteSpace(this.multicastAddress) || this.multicastPort <= 0) { throw new ArgumentException("Missing MulticastAddress setting."); } IPAddress ip = IPAddress.Parse(multicastAddress); IPEndPoint ipep = new IPEndPoint(ip, multicastPort); senderSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); senderSocket.SetSocketOption(SocketOptionLevel.Udp, SocketOptionName.NoDelay, 1); senderSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1); senderSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(ip)); senderSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, 1); senderSocket.Connect(ipep); receiverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); receiverSocket.ReceiveTimeout = 1000; IPEndPoint ipepRecv = new IPEndPoint(IPAddress.Any, multicastPort); IPAddress ipRecv = IPAddress.Parse(multicastAddress); receiverSocket.SetSocketOption(SocketOptionLevel.Udp, SocketOptionName.NoDelay, 1); receiverSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1); receiverSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(ipRecv, IPAddress.Any)); receiverSocket.Bind(ipepRecv); receiverThread = new Thread(new ThreadStart(ReceiveLoop)); receiverThread.Name = "Cache Eviction Listener"; receiverThread.Start(); }
public override void Init(OpenAccessClusterMsgHandler msgHandler, string serverName, string identifier, IOpenAccessClusterTransportLog log) { this.handler = msgHandler; this.log = log; if (!ConnectToRabbitMQ()) { throw new Exception("Failed to connect to RabbitMQ"); } StartConsumingFromRabbitMQ(millisecondsTimeout); }
public void Close() { closed = true; if (socket != null) { socket.Shutdown(SocketShutdown.Both); socket.Close(); } if (receiverThread != null) { receiverThread.Abort(); if (receiverThread.Join(2000)) { receiverThread = null; socket.Dispose(); } } handler = null; }
public void Init(OpenAccessClusterMsgHandler messageHandler, string serverName, string identifier, IOpenAccessClusterTransportLog log) { this.handler = messageHandler; this.log = log; if (string.IsNullOrWhiteSpace(this.multicastAddress) || this.multicastPort <= 0) { throw new ArgumentException("Missing MulticastAddress setting."); } IPAddress ip = IPAddress.Parse(multicastAddress); IPEndPoint ipep = new IPEndPoint(ip, multicastPort); socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connect(ipep); receiverThread = new Thread(new ThreadStart(ReceiveLoop)); receiverThread.Name = "Cache Eviction Listener"; receiverThread.Start(); }
/// <summary> /// Initializes transport after all properties have been set. /// </summary> /// <param name="msgHandler">The callback to use when messages are received</param> /// <param name="serverName">The connection id.</param> /// <param name="identifier">The identifier of the performance counters.</param> /// <param name="log">Logging instance</param> public abstract void Init(OpenAccessClusterMsgHandler msgHandler, string serverName, string identifier, IOpenAccessClusterTransportLog log);