private MonitorEvent(SocketEvents monitorEvent, [NotNull] string addr, [NotNull] object arg) { m_monitorEvent = monitorEvent; m_addr = addr; m_arg = arg; if (arg is int) m_flag = ValueInteger; else if (arg is AsyncSocket) m_flag = ValueChannel; else m_flag = 0; }
internal static Error TryChangeSocketEventRegistration(int port, SafeHandle socket, SocketEvents currentEvents, SocketEvents newEvents, IntPtr data) { bool release = false; try { socket.DangerousAddRef(ref release); return DangerousTryChangeSocketEventRegistration(port, (int)socket.DangerousGetHandle(), currentEvents, newEvents, data); } finally { if (release) { socket.DangerousRelease(); } } }
internal static extern Error TryChangeSocketEventRegistration(IntPtr port, IntPtr socket, SocketEvents currentEvents, SocketEvents newEvents, IntPtr data);
/// <summary> /// Create a new NetMQMonitorSocketEventArgs that contains the given monitor, address, and socket. /// </summary> /// <param name="monitor">The <see cref="NetMQMonitor"/> that raised this event.</param> /// <param name="address">The address of the event.</param> /// <param name="socketEvent">The type of socket event that occurred.</param> /// <param name="socket">The socket upon which this event occurred.</param> public NetMQMonitorSocketEventArgs([NotNull] NetMQMonitor monitor, [NotNull] string address, [NotNull] AsyncSocket socket, SocketEvents socketEvent) : base(monitor, address, socketEvent) { Socket = socket; }
/// <summary> /// Program entry. /// </summary> /// <param name="args">Process arguments.</param> public static void Main(string[] args) { Console.Title = "ProjectX V3 - Game Server"; try { config = new XmlConfig(); config.LoadConfig(Database.ServerDatabase.DatabaseLocation + "\\Config.xml"); } catch (Exception e) { Console.WriteLine("Could not load the config."); Console.WriteLine("Error:"); Console.WriteLine(e); Console.ReadLine(); return; } if (!Database.ServerDatabase.Load()) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Could not load the database."); Console.ReadLine(); return; } Threads.GlobalThreads.Start(); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Starting the server..."); try { Network.GameAuth.Start(); SocketEvents sockEvents = new SocketEvents(); sockEvents.OnConnection = new ConnectionEvent(Network.NetworkConnections.Handle_Connection); sockEvents.OnDisconnection = new ConnectionEvent(Network.NetworkConnections.Handle_Disconnection); sockEvents.OnReceive = new BufferEvent(Network.NetworkConnections.Handle_Receive); BeginServer(sockEvents, config.ReadInt32("GamePort")); ProjectX_V3_Lib.Native.Kernel32.SetConsoleCtrlHandler( new ProjectX_V3_Lib.Native.Kernel32.ConsoleEventHandler(Console_CloseEvent), true); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("The server is open..."); Console.ResetColor(); } catch (Exception e) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Could not open the server..."); Console.WriteLine(e.ToString()); Console.ReadLine(); return; } while (true) { HandleCmd(Console.ReadLine()); } }
public MonitorEvent(SocketEvents monitorEvent, [NotNull] string addr, [NotNull] AsyncSocket arg) : this(monitorEvent, addr, (object)arg) { }
public MonitorEvent(SocketEvents monitorEvent, string addr, AsyncSocket arg) : this(monitorEvent, addr, (object)arg) { }
private void ValueServer_OnBaseReceive(SocketEvents.ReceiveEventArgs e) { if (OnReceive != null) OnReceive(e); }
/// <summary> /// Create a new NetMQMonitorSocketEventArgs that contains the given monitor, address, and socket. /// </summary> /// <param name="monitor">The <see cref="NetMQMonitor"/> that raised this event.</param> /// <param name="address">The address of the event.</param> /// <param name="socketEvent">The type of socket event that occurred.</param> /// <param name="socket">The socket upon which this event occurred.</param> public NetMQMonitorSocketEventArgs(NetMQMonitor monitor, string address, AsyncSocket socket, SocketEvents socketEvent) : base(monitor, address, socketEvent) { Socket = socket; }
/// <summary> /// Create a new NetMQMonitorErrorEventArgs that contains the given monitor, address, and error-code. /// </summary> /// <param name="monitor">The <see cref="NetMQMonitor"/> that raised this event.</param> /// <param name="address">The address of the event.</param> /// <param name="socketEvent">The type of socket event that occurred.</param> /// <param name="errorCode">The error code associated with this event.</param> public NetMQMonitorErrorEventArgs(NetMQMonitor monitor, string address, ErrorCode errorCode, SocketEvents socketEvent) : base(monitor, address, socketEvent) { ErrorCode = errorCode; }
/// <summary> /// Create a new NetMQMonitorIntervalEventArgs containing the given NetMQMonitor, address, and interval. /// </summary> /// <param name="monitor">the NetMQMonitor</param> /// <param name="address">The a string denoting the address</param> /// <param name="interval">The interval, in milliseconds.</param> /// <param name="socketEvent">The type of socket event that occurred.</param> public NetMQMonitorIntervalEventArgs(NetMQMonitor monitor, string address, int interval, SocketEvents socketEvent) : base(monitor, address, socketEvent) { Interval = interval; }
/// <summary> /// Create a new NetMQMonitorEventArgs that contains the given monitor and address. /// </summary> /// <param name="monitor">The <see cref="NetMQMonitor"/> that raised this event.</param> /// <param name="address">The address of the event.</param> /// <param name="socketEvent">The type of socket event that occurred.</param> protected NetMQMonitorEventArgs(NetMQMonitor monitor, string address, SocketEvents socketEvent) { Monitor = monitor; Address = address; SocketEvent = socketEvent; }
internal static Error TryChangeSocketEventRegistration(int port, SafeHandle socket, SocketEvents currentEvents, SocketEvents newEvents, IntPtr data) { bool release = false; try { socket.DangerousAddRef(ref release); return(DangerousTryChangeSocketEventRegistration(port, (int)socket.DangerousGetHandle(), currentEvents, newEvents, data)); } finally { if (release) { socket.DangerousRelease(); } } }
internal static extern Error DangerousTryChangeSocketEventRegistration(int port, int socket, SocketEvents currentEvents, SocketEvents newEvents, IntPtr data);
/// <summary> /// Begins the server. /// </summary> /// <param name="sockEvents">The socket events.</param> /// <param name="port">The port.</param> private static void BeginServer(SocketEvents sockEvents, int port) { SocketServer server = new SocketServer(sockEvents); server.Start(config.ReadString("IPAddress"), port); }
/// <summary> /// 反注册一条事件 /// </summary> /// <param name="socketEvent">Socket事件</param> /// <param name="callback">回调</param> public void Off(SocketEvents socketEvent, Action <object> callback) { emmiter.Off(socketEvent, callback); }
internal static partial Error TryChangeSocketEventRegistration(IntPtr port, SafeHandle socket, SocketEvents currentEvents, SocketEvents newEvents, IntPtr data);
/// <summary> /// 触发一个Socket事件 /// </summary> /// <param name="socketEvent">Socket事件</param> /// <param name="payload">载荷</param> public void Trigger(SocketEvents socketEvent, object payload) { emmiter.Trigger(socketEvent, payload); }
/// <summary> /// Create a new NetMQMonitorSocketEventArgs that contains the given monitor, address, and socket. /// </summary> /// <param name="monitor">The <see cref="NetMQMonitor"/> that raised this event.</param> /// <param name="address">The address of the event.</param> /// <param name="socketEvent">The type of socket event that occurred.</param> /// <param name="socket">The socket upon which this event occurred.</param> public NetMQMonitorSocketEventArgs( NetMQMonitor monitor, string address, AsyncSocket socket, SocketEvents socketEvent) : base(monitor, address, socketEvent) { Socket = socket; }
internal static extern Error TryChangeSocketEventRegistration(int port, int socket, SocketEvents currentEvents, SocketEvents newEvents, IntPtr data);
/// <summary> /// Register the given events to monitor on the given endpoint. /// </summary> /// <param name="addr">a string denoting the endpoint to monitor. If this is null - monitoring is stopped.</param> /// <param name="events">the SocketEvent to monitor for</param> /// <exception cref="NetMQException">Maximum number of sockets reached.</exception> /// <exception cref="ProtocolNotSupportedException">The protocol of <paramref name="addr"/> is not supported.</exception> /// <exception cref="TerminatingException">The socket has been stopped.</exception> public void Monitor([CanBeNull] string addr, SocketEvents events) { CheckContextTerminated(); // Support de-registering monitoring endpoints as well if (addr == null) { StopMonitor(); return; } string address; string protocol; DecodeAddress(addr, out address, out protocol); CheckProtocol(protocol); // Event notification only supported over inproc:// if (protocol != Address.InProcProtocol) throw new ProtocolNotSupportedException($"In SocketBase.Monitor({addr},), protocol must be inproc"); // Register events to monitor m_monitorEvents = events; m_monitorSocket = Ctx.CreateSocket(ZmqSocketType.Pair); // Never block context termination on pending event messages const int linger = 0; try { m_monitorSocket.SetSocketOption(ZmqSocketOption.Linger, linger); } catch (NetMQException) { StopMonitor(); throw; } // Spawn the monitor socket endpoint try { m_monitorSocket.Bind(addr); } catch (NetMQException) { StopMonitor(); throw; } }
public MonitorEvent(SocketEvents monitorEvent, [NotNull] string addr, ErrorCode arg) : this(monitorEvent, addr, (int)arg) { }
/// <summary> /// Create a new NetMQMonitorIntervalEventArgs containing the given NetMQMonitor, address, and interval. /// </summary> /// <param name="monitor">the NetMQMonitor</param> /// <param name="address">The a string denoting the address</param> /// <param name="interval">The interval, in milliseconds.</param> /// <param name="socketEvent">The type of socket event that occurred.</param> public NetMQMonitorIntervalEventArgs([NotNull] NetMQMonitor monitor, [NotNull] string address, int interval, SocketEvents socketEvent) : base(monitor, address, socketEvent) { Interval = interval; }
internal static extern Error TryChangeSocketEventRegistration(IntPtr port, SafeHandle socket, SocketEvents currentEvents, SocketEvents newEvents, IntPtr data);
/// <summary> /// If there is a monitor-socket, close it and set monitor-events to 0. /// </summary> private void StopMonitor() { if (m_monitorSocket != null) { m_monitorSocket.Close(); m_monitorSocket = null; m_monitorEvents = 0; } }
/// <summary> /// Create a new monitor object /// </summary> /// <param name="monitoredSocket">Socket to monitor</param> /// <param name="endpoint">Bind endpoint</param> /// <param name="eventsToMonitor">Flag enum of the events to monitored</param> public NetMQMonitor([NotNull] NetMQSocket monitoredSocket, [NotNull] string endpoint, SocketEvents eventsToMonitor) { Endpoint = endpoint; Timeout = TimeSpan.FromSeconds(0.5); monitoredSocket.Monitor(endpoint, eventsToMonitor); m_monitoringSocket = new PairSocket(); m_monitoringSocket.Options.Linger = TimeSpan.Zero; m_monitoringSocket.ReceiveReady += Handle; m_ownsMonitoringSocket = true; }
/// <summary> /// Create a new NetMQMonitorEventArgs that contains the given monitor and address. /// </summary> /// <param name="monitor">The <see cref="NetMQMonitor"/> that raised this event.</param> /// <param name="address">The address of the event.</param> /// <param name="socketEvent">The type of socket event that occurred.</param> protected NetMQMonitorEventArgs([NotNull] NetMQMonitor monitor, [NotNull] string address, SocketEvents socketEvent) { Monitor = monitor; Address = address; SocketEvent = socketEvent; }
/// <summary> /// Create a new NetMQMonitorErrorEventArgs that contains the given monitor, address, and error-code. /// </summary> /// <param name="monitor">The <see cref="NetMQMonitor"/> that raised this event.</param> /// <param name="address">The address of the event.</param> /// <param name="socketEvent">The type of socket event that occurred.</param> /// <param name="errorCode">The error code associated with this event.</param> public NetMQMonitorErrorEventArgs([NotNull] NetMQMonitor monitor, [NotNull] string address, ErrorCode errorCode, SocketEvents socketEvent) : base(monitor, address, socketEvent) { ErrorCode = errorCode; }