コード例 #1
0
ファイル: MonitorPoll.cs プロジェクト: oskarwkarlsson/netmq
        /// <summary>
        /// 
        /// </summary>
        /// <param name="context">The context of the socket</param>
        /// <param name="socket">Socket to monitor</param>
        /// <param name="address">Monitoring address to use</param>
        /// <param name="monitoringEventsHandler">The events handler interface</param>
        public MonitorPoll(Context context, BaseSocket socket,
			string address, IMonitoringEventsHandler monitoringEventsHandler)
        {
            Socket = socket;
            MonitorAddress = address;
            m_monitoringEventsHandler = monitoringEventsHandler;
            Context = context;
            Timeout = TimeSpan.FromSeconds(1);
        }
コード例 #2
0
        void ISocketEventListener.OnWrite(BaseSocket sock, byte[] buf, int offset, int length)
        {
            int tim = (int)m_listener[Options.KEEP_ALIVE];

            if (tim > 0)
            {
                m_timer.Change(tim, tim);
            }

            m_listener.BytesWritten(buf, offset, length);
        }
コード例 #3
0
        void ISocketEventListener.OnConnect(BaseSocket sock)
        {
#if !NO_SSL
            if ((bool)m_listener[Options.SSL])
            {
                AsyncSocket s = sock as AsyncSocket;
                m_listener[Options.REMOTE_CERTIFICATE] = s.RemoteCertificate;
            }
#endif
            m_listener.Connected();
        }
コード例 #4
0
        bool ISocketEventListener.OnAccept(BaseSocket newsocket)
        {
            m_sock = newsocket;
            InitializeStream();
            m_listener.Accepted();

            // Don't accept any more connections until this one closes
            // yes, it will look like we're still listening until the old sock is free'd by GC.
            // don't want OnClose() to fire, though, so we can't close the previous sock.
            return(false);
        }
コード例 #5
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter Id : ");
            Id = Console.ReadLine();
            Console.WriteLine("Enter Match Id : ");
            matchId   = Console.ReadLine();
            tcpSocket = new ConnectSocket(512, "127.0.0.1", 1618);
            tcpSocket.SocketActionEventHandler += TcpSocket_OnSocketAction;

            Console.ReadLine();
        }
コード例 #6
0
        /// <summary>
        /// Listens for an inbound connection.
        /// </summary>
        public override void Accept()
        {
            AsyncSocket s = new AsyncSocket(null, this, (bool)m_listener[Options.SSL], false);

            s.LocalCertificate = m_listener[Options.LOCAL_CERTIFICATE] as
                                 System.Security.Cryptography.X509Certificates.X509Certificate2;

            m_sock = s;
            m_sock.Accept(new Address((int)m_listener[Options.PORT]));
            m_sock.RequestAccept();
        }
コード例 #7
0
        public ChatNetworkService(BaseSocket socket, ConversationInfo info) : base(info) // string username
        {
            this.socket = socket;

            socket.OnMessageRecieved       += OnMessageRecievedHandler;
            socket.OnSocketDisconnect      += OnDisconnectHandler;
            socket.OnMessageParseException += OnMessageParseExceptionHandler;
            //socket.OnSocketDisconnect += () =>
            //{
            //    OnServiceDisconnect?.Invoke();
            //};
        }
コード例 #8
0
    private void OnPartPlaced(BasePart part, BaseSocket socket)
    {
        if (part.GetComponent <AddonRemoveGrass>() == null)
        {
            return;
        }

        if (RemoveGrass)
        {
            StartCoroutine(RemoveGrassToPosition(part.transform.position, RemoveGrassRadius));
        }
    }
コード例 #9
0
 public Boolean init()
 {
     IFacade    = new IFacade();
     baseSocket = new BaseSocket();
     baseSocket.Socket(ProfileView.profile.serverIP, Int32.Parse(ProfileView.profile.serverPort));
     baseSocket.onRecive    += onRecive;
     baseSocket.onConnect   += onConnect;
     baseSocket.onDisconect += onDisconect;
     baseSocket.onSent      += onSent;
     baseSocket.connect();
     return(true);
 }
コード例 #10
0
        public BaseSocket UpdateWirelessSocket(string name, BaseSocket wirelessSocket)
        {
            if (wirelessSocket.Name != name)
            {
                throw new ArgumentException("name does not name of wireless socket");
            }

            var socket = _wirelessSockets.First(n => n.Name == name);

            socket = wirelessSocket;

            return(socket);
        }
コード例 #11
0
    void EndAccept()
    {
        Socket serverClientSocket = EndAccept(...);
        // create a base socket handler.....
        BaseSocket clientSocket = new BaseSocket();

        _clients.Add(clientSocket);
        // bind the ondata event of the client and pass it to the clientondata event of the server.
        // Start receiving from the socket.
        clientSocket.Start(clientSocket);
        // accept new clients.
        StartAccept();
    }
コード例 #12
0
    public BaseServer()
    {
        _inited = true;

        _socket = new BaseSocket();
        _socket.setServer(this);
        _socket.setConnectCall(onConnect);
        _socket.setConnectFailedCall(onConnectFailed);
        _socket.setCloseCall(onClose);
        _socket.setCreateResponseFunc(createResponse);

        NetControl.addSocket(_socket);
    }
コード例 #13
0
ファイル: BaseSocket.cs プロジェクト: P79N6A/projects
 public static byte[] Read(Stream stream, byte[] end)
 {
     using (MemoryStream ms = new MemoryStream()) {
         byte[] data  = new byte[1];
         int    bytes = data.Length;
         while (bytes > 0 && BaseSocket.findBytes(ms.ToArray(), end, 0) == -1)
         {
             bytes = stream.Read(data, 0, data.Length);
             ms.Write(data, 0, data.Length);
         }
         return(ms.ToArray());
     }
 }
コード例 #14
0
        /// <summary>
        /// Performs TCP connection and sets up reader/writer.
        /// Allows different control port to be used
        /// </summary>
        /// <param name="sock">
        ///  Socket instance
        /// </param>
        /// <param name="remoteHost">
        /// address of remote host
        /// </param>
        /// <param name="controlPort">
        /// port for control stream
        /// </param>
        /// <param name="timeout">
        /// the length of the timeout, in milliseconds
        /// </param>
        /// <param name="encoding">
        /// encoding to use for control channel
        /// </param>
        internal void Initialize(BaseSocket sock, string remoteHost, int controlPort,
                                 int timeout, Encoding encoding)
        {
            this.remoteHost  = remoteHost;
            this.controlPort = controlPort;
            this.timeout     = timeout;

            // establish socket connection & set timeouts
            controlSock = sock;
            ConnectSocket(controlSock, remoteHost, controlPort);
            Timeout = timeout;

            InitStreams(encoding);
        }
コード例 #15
0
    protected void Write(Stream stream, SocketMessager messager)
    {
        MemoryStream ms = new MemoryStream();

        byte[] buff = Encoding.UTF8.GetBytes(messager.GetCanParseString());
        ms.Write(buff, 0, buff.Length);
        if (messager.Arg != null)
        {
            buff = Deflate.Compress(BaseSocket.Serialize(messager.Arg));
            ms.Write(buff, 0, buff.Length);
        }
        this.Write(stream, ms.ToArray());
        ms.Close();
    }
コード例 #16
0
        public void disconect()
        {
            try { baseSocket.disconnect(); } catch { }

            baseSocket = null;
            try { baseSocket.onRecive -= onRecive; }catch { }
            try { baseSocket.onConnect -= onConnect; } catch { }
            try { baseSocket.onDisconect -= onDisconect; } catch { }
            try { baseSocket.onSent -= onSent; } catch { }

            try
            { remove(); }
            catch { }
        }
コード例 #17
0
    private void OnPartEdited(BasePart part, BaseSocket socket)
    {
        if (part != Part)
        {
            return;
        }

        if (EditionObject != null)
        {
            GameObject Temp = Instantiate(EditionObject, part.transform.position, part.transform.rotation);

            Destroy(Temp, LifeTime);
        }
    }
コード例 #18
0
 public async Task <bool> ToggleWirelessSocketState(BaseSocket wirelessSocket)
 {
     try
     {
         var requestParams = SetPilightQueryParams(wirelessSocket);
         var request       = new HttpRequestMessage(HttpMethod.Get, requestParams);
         var response      = await _httpClient.SendAsync(request);
     }
     catch (Exception e)
     {
         // nothing to do here
     }
     return(true);
 }
コード例 #19
0
        /// <summary>
        /// Listens for an inbound connection.
        /// </summary>
        public override void Accept()
        {
            if (m_accept == null)
            {
                m_accept = new AsyncSocket(null, this, (bool)m_listener[Options.SSL], false);

                ((AsyncSocket)m_accept).LocalCertificate = m_listener[Options.LOCAL_CERTIFICATE] as X509Certificate2;

                Address addr = new Address((string)m_listener[Options.NETWORK_HOST],
                                           (int)m_listener[Options.PORT]);

                m_accept.Accept(addr);
            }
            m_accept.RequestAccept();
        }
コード例 #20
0
 internal void SetSocketTimeout(BaseSocket sock, int timeout)
 {
     if (timeout > 0)
     {
         try
         {
             sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, timeout);
             sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, timeout);
         }
         catch (SocketException exception)
         {
             this.log.Warn("Failed to set socket timeout: " + exception.Message);
         }
     }
 }
コード例 #21
0
 /// <summary>
 /// Closes underlying sockets
 /// </summary>
 internal override void Close()
 {
     try
     {
         if (acceptedSock != null)
         {
             acceptedSock.Close();
             acceptedSock = null;
         }
     }
     finally
     {
         sock.Close();
     }
 }
コード例 #22
0
 internal override void Close()
 {
     try
     {
         if (this.acceptedSock != null)
         {
             this.acceptedSock.Close();
             this.acceptedSock = null;
         }
     }
     finally
     {
         base.sock.Close();
     }
 }
コード例 #23
0
 internal void Kill()
 {
     try
     {
         if (controlSock != null)
         {
             controlSock.Close();
         }
         controlSock = null;
     }
     catch (Exception e)
     {
         log.Debug("Killed socket", e);
     }
     log.Info("Killed control socket");
 }
コード例 #24
0
        /// <summary>
        /// Is the socket occopied in the group buildings?
        /// </summary>
        /// <param name="socketInstance">the instance of the socket you are checking.</param>
        /// <returns></returns>
        public virtual bool IsGroupSocketOccoupied(BaseSocket socketInstance)
        {
            BaseSocket socket;

            for (int i = 0; i < buildings.Count; i++)
            {
                socket = buildings.ElementAt(i).ReturnSocket(socketInstance.transform.position, socketInstance.receiveType);

                if (socket != null && socket.building != socketInstance.building && !socket.isActive)
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #25
0
    public static void OnRecvUDP(byte[] recvBuffer, int length, BaseSocket socket)
    {
        //MultiGameView.Log("Recieve collect Player Request ServiceManager:");
        byte commandType;
        //CommonTrace.Log(string.Format("收到UDP:数据类型{0}", packageType)); 
        var binaryHead = PackageHelper.BytesToStuct<PkgHead>(recvBuffer);

        commandType = binaryHead.MasterMsgType;

        int ret = binaryHead.DataLength;

        if (ServiceMap.ContainsKey(commandType))
        {
            ServiceMap[commandType].SaveResponseHandleToInvoke(recvBuffer.Take(ret).ToArray(), socket.GetSocketId(), commandType);
        }
    }
コード例 #26
0
ファイル: FTPControlSocket.cs プロジェクト: mo5h/omeo
        /// <summary>
        /// Performs TCP connection and sets up reader/writer.
        /// Allows different control port to be used
        /// </summary>
        /// <param name="sock">
        ///  Socket instance
        /// </param>
        /// <param name="remoteHost">
        /// address of remote host
        /// </param>
        /// <param name="controlPort">
        /// port for control stream
        /// </param>
        /// <param name="timeout">
        /// the length of the timeout, in milliseconds
        /// </param>
        internal void Initialize(BaseSocket sock, IPAddress remoteHost, int controlPort, int timeout)
        {
            this.remoteHost  = remoteHost;
            this.controlPort = controlPort;
            this.timeout     = timeout;

            log = Logger.GetLogger(typeof(FTPControlSocket));

            // establish socket connection & set timeouts
            controlSock = sock;
            ConnectSocket(controlSock, remoteHost, controlPort);
            Timeout = timeout;

            InitStreams();
            ValidateConnection();
        }
コード例 #27
0
 internal void Kill()
 {
     try
     {
         if (this.controlSock != null)
         {
             this.controlSock.Close();
         }
         this.controlSock = null;
     }
     catch (Exception exception)
     {
         this.log.Debug("Killed socket", exception);
     }
     this.log.Info("Killed control socket");
 }
コード例 #28
0
 internal FTPControlSocket()
 {
     this.log = Logger.GetLogger("FTPControlSocket");
     this.synchronizePassiveConnections = false;
     this.strictReturnCodes             = false;
     this.remoteHost                = null;
     this.remoteAddr                = null;
     this.controlPort               = -1;
     this.controlSock               = null;
     this.timeout                   = 0;
     this.writer                    = null;
     this.reader                    = null;
     this.activePortRange           = null;
     this.activeIPAddress           = null;
     this.nextPort                  = 0;
     this.autoPassiveIPSubstitution = false;
 }
コード例 #29
0
 public void AcceptAsync()
 {
     if (!IsClient)
     {
         var acceptArgs = SocketPool.Pop();
         acceptArgs.Completed += OnSocketCompleted;
         var willRaiseEvent = BaseSocket.AcceptAsync(acceptArgs);
         if (!willRaiseEvent)
         {
             AcceptHandle(acceptArgs);
         }
     }
     else
     {
         RaiseFault("Unable to create connections on a client socket.");
     }
 }
コード例 #30
0
ファイル: SocketConnection.cs プロジェクト: nikes/Link
 private void StartReceive()
 {
     if (State != ConnectionState.Working)
     {
         return;
     }
     try
     {
         if (!BaseSocket.ReceiveAsync(SocketReceiveArgs))
         {
             ReceiveProcess(SocketReceiveArgs);
         }
     }
     catch
     {
         Close();
     }
 }
コード例 #31
0
ファイル: BaseSocket.cs プロジェクト: ysb860331/MySocket
    public static SocketMessager Parse(byte[] data)
    {
        if (data == null)
        {
            return(new SocketMessager("NULL"));
        }
        if (data.Length == 1 && data[0] == 0)
        {
            return(SocketMessager.SYS_TEST_LINK);
        }
        int    idx  = BaseSocket.findBytes(data, new byte[] { 13, 10 }, 0);
        string text = Encoding.UTF8.GetString(data, 0, idx);

        string[]       loc1 = text.Split(new string[] { "\t" }, 4, StringSplitOptions.None);
        string         loc2 = loc1[0];
        string         loc3 = loc1.Length > 1 ? loc1[1].Replace("\\\\", "\\").Replace("\\t", "\t").Replace("\\n", "\r\n") : null;
        string         loc4 = loc1.Length > 2 ? loc1[2].Replace("\\\\", "\\").Replace("\\t", "\t").Replace("\\n", "\r\n") : null;
        string         loc5 = loc1.Length > 3 ? loc1[3] : null;
        SocketMessager messager;

        using (MemoryStream ms = new MemoryStream()) {
            ms.Write(data, idx + 2, data.Length - idx - 2);
            messager = new SocketMessager(loc3, loc4, ms.Length > 0 ? BaseSocket.Deserialize(ms.ToArray()) : null);
            //using (DeflateStream ds = new DeflateStream(ms, CompressionMode.Decompress)) {
            //	using (MemoryStream msOut = new MemoryStream()) {
            //		ds.CopyTo(msOut);
            //		messager = new SocketMessager(loc3, loc4, ms.Length > 0 ? BaseSocket.Deserialize(ms.ToArray()) : null);
            //	}
            //}
        }
        if (int.TryParse(loc2, out idx))
        {
            messager._id = idx;
        }
        if (!string.IsNullOrEmpty(loc5))
        {
            DateTime.TryParse(loc5, out messager._remoteTime);
        }
        if (messager._arg is Exception)
        {
            messager._exception = messager._arg as Exception;
        }
        return(messager);
    }
コード例 #32
0
ファイル: Proxy.cs プロジェクト: oskarwkarlsson/netmq
 public Proxy(BaseSocket frontend, BaseSocket backend, BaseSocket control)
 {
     m_frontend = frontend;
     m_backend = backend;
     m_control = control;
 }
コード例 #33
0
ファイル: MonitorPoll.cs プロジェクト: oskarwkarlsson/netmq
        /// <summary>
        /// Creating the monitoring socket, this method automaticlly called by the start method
        /// if you want to receive events that happen before the call to the start mehod call
        /// this method earlier in your code
        /// </summary>
        public void Init()
        {
            if (!m_initialized)
            {
                // in case the sockets is created in another thread
                Thread.MemoryBarrier();

                ZMQ.SocketMonitor(Socket.SocketHandle, MonitorAddress, m_monitoringEventsHandler.Events);

                MonitoringSocket = Context.CreatePairSocket();

                MonitoringSocket.Connect(MonitorAddress);

                m_initialized = true;
            }
        }
コード例 #34
0
ファイル: SocketOptions.cs プロジェクト: knocte/netmq
 public SocketOptions(BaseSocket socket)
 {
     m_socket = socket;
 }