Esempio n. 1
0
 public MonitorEvent(SocketEvent monitorEvent, String addr, Object arg)
 {
     this.m_monitorEvent = monitorEvent;
     this.m_addr = addr;
     this.m_arg = arg;
     if (arg is int)
         m_flag = ValueInteger;
     else if (arg is System.Net.Sockets.Socket)
         m_flag = ValueChannel;
     else
         m_flag = 0;
 }
Esempio n. 2
0
        private MonitorEvent(SocketEvent 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;
        }
Esempio n. 3
0
 public MonitorEvent(SocketEvent monitorEvent, String addr, Object arg)
 {
     this.m_monitorEvent = monitorEvent;
     this.m_addr         = addr;
     this.m_arg          = arg;
     if (arg is int)
     {
         m_flag = ValueInteger;
     }
     else if (arg is System.Net.Sockets.Socket)
     {
         m_flag = ValueChannel;
     }
     else
     {
         m_flag = 0;
     }
 }
Esempio n. 4
0
    public Socket GetSocket(SocketEvent socketEvent)
    {
        Socket socket;


        if (sockets.ContainsKey(socketEvent))
        {
            return(sockets[socketEvent]);
        }
        else
        {
            socket = Socket.Connect(ServerHelper.SERVERPATH + "/" + socketEvent.ToString());
            sockets.Add(socketEvent, socket);
        }


        return(socket);
    }
Esempio n. 5
0
        public void CreateRoom(string roomName)
        {
            aftercreaterooms.SetActive(true);
            createandjoin.SetActive(false);

            roomnameui.text = ("Room : " + inputroomnameuser.text);

            /*if (inputroomnameuser.text != null)
             * {
             *  failpopup.SetActive(true);
             * }*/

            SocketEvent socketEvent = new SocketEvent("CreateRoom", inputroomnameuser.text);

            string toJsonStr = JsonUtility.ToJson(socketEvent);

            ws.Send(toJsonStr);
        }
 public void AddNetworkEvent(SocketEvent newEvent)
 {
     try
     {
         events.Add(newEvent);
     }
     catch (Exception ex)
     {
         if (ex is IndexOutOfRangeException)
         {
             Debug.LogWarning("Index was out of range while adding an event to the queue.");
         }
         else
         {
             Debug.LogWarning("UNKNOWN WARNING:" + ex.InnerException + "\n" + ex.StackTrace);
         }
     }
 }
Esempio n. 7
0
    public void AnswerButton()
    {
        if (answerInputF.text != "")
        {
            SocketEvent sendAnswerData = new SocketEvent();
            sendAnswerData.eventName = "SendAnswer";
            sendAnswerData.token     = studenIDandTokenInputF.text;
            sendAnswerData.answer    = answerInputF.text;

            string stringAnswer = JsonUtility.ToJson(sendAnswerData);
            ws.Send(stringAnswer);
            Debug.LogError(stringAnswer);
        }
        else
        {
            Debug.Log("Nothing Text");
        }
    }
Esempio n. 8
0
 private MonitorEvent(SocketEvent monitorEvent, String addr, Object arg)
 {
     this.m_monitorEvent = monitorEvent;
     this.m_addr         = addr;
     this.m_arg          = arg;
     if (arg is int)
     {
         m_flag = ValueInteger;
     }
     else if (arg is AsyncSocket)
     {
         m_flag = ValueChannel;
     }
     else
     {
         m_flag = 0;
     }
 }
Esempio n. 9
0
 private void ProcessClientEvent(SocketEvent e)
 {
     switch (e.type)
     {
     case SocketEvent.Type.Connect:
         // make RPC calls
         for (int i = 0; i < 10; i++)
         {
             NetworkManager.Send(CLIENT_NAME, CGProtoMgr._PACKET_TEST_CG_RPC("test"),
                                 (token, packet) =>
             {
                 _PACKET_TEST_GC_RPC p = ( _PACKET_TEST_GC_RPC )packet;
                 Logger.Log(p.dto.value);
             });
         }
         break;
     }
 }
 void Close(bool bForceReconnect = false)
 {
     if (client != null)
     {
         client.Close();
         client = null;
     }
     if (streamToServer != null)
     {
         streamToServer.Close();
         streamToServer = null;
     }
     if (bForceReconnect)
     {
         SocketEvent socketEvent = new SocketEvent(EventType.ReconnectInstantly);
         socketsEventsQueue.Enqueue(socketEvent);
     }
 }
        public void RegisterPW(string password)
        {
            password = passwordRegis.text;

            if (userNameRegis.text == "" || userIDRegis.text == "" || passwordRegis.text == "" || rePasswordRegis.text == "" || passwordRegis.text != rePasswordRegis.text)
            {
                registerFail.SetActive(true);
            }

            else
            {
                SocketEvent socketEvent = new SocketEvent("RegisterPW", password);

                string toJsonStr = JsonUtility.ToJson(socketEvent);

                ws.Send(toJsonStr);
            }
        }
Esempio n. 12
0
        public void SendMessage()
        {
            print(sendM);
            if (inputText.text == "" || ws.ReadyState != WebSocketState.Open)
            {
                return;
            }
            SocketEvent socketEvent = new SocketEvent("SendMessage", "", "", sendM, "", inputText.text);

            //MessageData messageData = new MessageData();
            //messageData.username = inputUsername.text;
            //messageData.message = inputText.text;

            string toJsonStr = JsonUtility.ToJson(socketEvent);

            ws.Send(toJsonStr);
            inputText.text = "";
        }
Esempio n. 13
0
        public void JoinRoomNext()
        {
            if (ws.ReadyState == WebSocketState.Open)
            {
                SocketEvent socketEvent = new SocketEvent("JoinRoom", "Room : " + InputJoin.text, InputUser.text);

                string toJsonStr = JsonUtility.ToJson(socketEvent);

                ws.Send(toJsonStr);
            }

            //rootJoinRoom.SetActive(false);
            //rootMessenger.SetActive(true);

            join = InputJoin.text;
            //JoinRoom("Room : " + InputJoin.text);
            RoomName.text = "Room : " + InputJoin.text;
        }
Esempio n. 14
0
        public void Register(string dataRegister)
        {
            dataRegister = inputFields[3].text + "#" + inputFields[4].text + "#" + inputFields[2].text;
            if (inputFields[2].text != "")
            {
                if (inputFields[3].text != "")
                {
                    if (inputFields[4].text != "")
                    {
                        if (inputFields[5].text != "")
                        {
                            if (inputFields[4].text == inputFields[5].text)
                            {
                                SocketEvent socketEvent = new SocketEvent("Register", dataRegister, userName);

                                string toJsonStr = JsonUtility.ToJson(socketEvent);

                                ws.Send(toJsonStr);
                            }
                            else if (inputFields[4].text != inputFields[5].text)
                            {
                                error[5].SetActive(true);
                            }
                        }
                        else if (inputFields[5].text == "")
                        {
                            error[2].SetActive(true);
                        }
                    }
                    else if (inputFields[4].text == "")
                    {
                        error[2].SetActive(true);
                    }
                }
                else if (inputFields[3].text == "")
                {
                    error[2].SetActive(true);
                }
            }
            else if (inputFields[2].text == "")
            {
                error[2].SetActive(true);
            }
        }
Esempio n. 15
0
    public void AnswerButton()
    {
        for (int i = 0; i < numbers.Length; i++)
        {
            if (i == findAnswer)
            {
                SocketEvent sendAnswerData = new SocketEvent();
                sendAnswerData.eventName = "SendAnswer";
                sendAnswerData.token     = myToken;
                sendAnswerData.answer    = numbers[i].ToString();

                string stringAns = JsonUtility.ToJson(sendAnswerData);
                ws.Send(stringAns);

                Debug.Log(stringAns);
                break;
            }
        }
    }
Esempio n. 16
0
        private void ProcessClientEvent(SocketEvent e)
        {
            switch (e.type)
            {
            case SocketEvent.Type.Connect:
                this.InitBattle();
                break;

            case SocketEvent.Type.Receive:
                if (e.packet.module == CGModule.BATTLE && e.packet.command == CGCommand.GC_FRAME)
                {
                    this._lBattle?.ProcessServerKeyFrame((( _PACKET_BATTLE_GC_FRAME )e.packet).dto);
                }
                break;

            case SocketEvent.Type.Close:
                break;
            }
        }
Esempio n. 17
0
        public void LogIn()
        {
            if (IDnameLogin.text == "" || PassLogin.text == "")
            {
                popupOk.SetActive(true);
                Oktext.text = "Please input all field";
                return;
            }


            if (ws.ReadyState == WebSocketState.Open)
            {
                SocketEvent socketEvent = new SocketEvent("Login", "", IDnameLogin.text, "", PassLogin.text, "");

                string jsonStr = JsonUtility.ToJson(socketEvent);

                ws.Send(jsonStr);
            }
        }
Esempio n. 18
0
    protected void Update()
    {
        lock (_lockObj)
        {
            while (_recvMsgList.Count > 0)
            {
                byte[] data = _recvMsgList[0];
                Received?.Invoke(data);
                _recvMsgList.RemoveAt(0);
            }

            while (_socketEventList.Count > 0)
            {
                SocketEvent se = _socketEventList[0];
                Completed?.Invoke(se._action, se._msg);
                _socketEventList.RemoveAt(0);
            }
        }
    }
Esempio n. 19
0
        public void SendMessage()
        {
            if (ChatText.text == "" || websocket.ReadyState != WebSocketState.Open)
            {
                return;
            }
            MessageData messageData = new MessageData();

            messageData.username = Username;
            messageData.message  = ChatText.text;

            string      toJsonStr   = JsonUtility.ToJson(messageData);
            SocketEvent socketEvent = new SocketEvent("SendMessage", toJsonStr);
            string      fromJsonStr = JsonUtility.ToJson(socketEvent);

            websocket.Send(fromJsonStr);

            ChatText.text = "";
        }
Esempio n. 20
0
        private void JoinRoomHandler(SocketEvent receive)
        {
            Debug.Log(receive.data);

            if (receive.data == "success")
            {
                rootJoinRoom.SetActive(false);
                rootMessenger.SetActive(true);
                rootCreateFail.SetActive(false);
                rootJoinFail.SetActive(false);
            }
            else
            {
                rootJoinRoom.SetActive(false);
                rootJoinFail.SetActive(true);
                rootCreateFail.SetActive(false);
                rootMessenger.SetActive(false);
            }
        }
Esempio n. 21
0
        protected SocketBase(Ctx parent, int threadId, int sid)
            : base(parent, threadId)
        {
            m_tag           = 0xbaddecaf;
            m_ctxTerminated = false;
            m_destroyed     = false;
            m_lastTsc       = 0;
            m_ticks         = 0;
            m_rcvMore       = false;
            m_monitorSocket = null;
            m_monitorEvents = 0;

            m_options.SocketId = sid;

            m_endpoints = new Dictionary <string, Own>();
            m_pipes     = new List <Pipe>();

            m_mailbox = new Mailbox("socket-" + sid);
        }
Esempio n. 22
0
    public void AddCmdListener(int cmdID, Action <object> listener)
    {
        Dictionary <Action <object>, SocketEvent> eventListenrDic;

        _cmdEventDic.TryGetValue(cmdID, out eventListenrDic);
        if (eventListenrDic == null)
        {
            eventListenrDic = new Dictionary <Action <object>, SocketEvent>();
            _cmdEventDic.Add(cmdID, eventListenrDic);
        }
        if (eventListenrDic.ContainsKey(listener))
        {
            return;
        }
        SocketEvent evt = new SocketEvent();

        evt.Reset(listener);
        eventListenrDic.Add(listener, evt);
    }
Esempio n. 23
0
        public void LeaveRoom()
        {
            OnClickBackBtn();  //Back To Lobby Panal

            //Clear Old Text
            for (int i = 0; i < oldText.Count; i++)
            {
                Destroy(oldText[i].gameObject);
            }
            oldText.Clear();
            Debug.Log("Clear OldTextList countList : " + oldText.Count);

            //send request LeaveRoom to server
            SocketEvent dataToServer    = new SocketEvent("LeaveRoom", roomName);
            string      dataToServerStr = JsonUtility.ToJson(dataToServer);

            Debug.Log("Send to server:" + dataToServerStr);
            webSocket.Send(dataToServerStr);
        }
Esempio n. 24
0
        private MonitorEvent(SocketEvent 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;
            }
        }
Esempio n. 25
0
        public void Connect()
        {
            string url = $"ws://127.0.0.1:25500/";

            ws = new WebSocket(url);

            ws.OnMessage += OnMessage;

            ws.Connect();

            SocketEvent socketEvent = new SocketEvent("CreateRoom", "TestRoom01");

            string toJsonStr = JsonUtility.ToJson(socketEvent);

            ws.Send(toJsonStr);

            rootConnection.SetActive(false);
            rootMessenger.SetActive(true);
        }
        public void CreateRoomDelegate(SocketEvent state)
        {
            Debug.Log(state.data);

            if (state.data == "fail")
            {
                popupErrorCreate.SetActive(true);
                leaveButton.SetActive(true);
                roomNameTextGameob.SetActive(false);
                createRoomGameOb.SetActive(false);
                createRoomInputOb.SetActive(false);
            }
            else
            {
                JoinintoChat();
                createRoomGameOb.SetActive(false);
                createRoomInputOb.SetActive(false);
                Debug.Log(state);
            }
        }
Esempio n. 27
0
            public void Emit(string tag, SocketEvent socketEvent)
            {
                if (socketEvent != null)
                {
                    socketEvent.Tag = tag;
                }
                foreach (var key in _eventHandlers.Keys.Where(key => key.Equals(tag) || key.Equals("*")))
                {
                    _eventHandlers[key].Invoke(socketEvent);
                }
                ;

                foreach (var key in EventOnceHandlers.Keys.Where(key => key.Equals(tag)))
                {
                    _eventHandlers[key].Invoke(socketEvent);
                    Action <SocketEvent> eve;
                    EventOnceHandlers.TryRemove(tag, out eve);
                }
                ;
            }
Esempio n. 28
0
        /*public void StartExam()
         * {
         *  if (ansInput.text != "")
         *  {
         *      SocketEvent examData = new SocketEvent();
         *      examData.eventName = "StartExam";
         *      examData.token = studentidandtokenInput.text;
         *      examData.link = "";
         *
         *      string stringlink = JsonUtility.ToJson(examData);
         *      ws.Send(stringlink);
         *
         *      Debug.Log(stringlink);
         *  }
         *
         *  else
         *  {
         *      Debug.Log("do some thing");
         *  }
         * }*/

        public void Answer()
        {
            if (ansInput.text != "")
            {
                SocketEvent sendAnswerData = new SocketEvent();
                sendAnswerData.eventName = "SendAnswer";
                sendAnswerData.token     = studentidandtokenInput.text;
                sendAnswerData.ans       = ansInput.text;

                string stringAns = JsonUtility.ToJson(sendAnswerData);
                ws.Send(stringAns);

                Debug.Log(stringAns);
            }

            else
            {
                Debug.Log("do some thing");
            }
        }
Esempio n. 29
0
 public void OnClickJoinBtn()
 {
     //send request Join to server
     if (!string.IsNullOrEmpty(roomNameInputField.text))
     {
         SocketEvent dataToServer    = new SocketEvent("JoinRoom", roomNameInputField.text);
         string      dataToServerStr = JsonUtility.ToJson(dataToServer);
         webSocket.Send(dataToServerStr);
     }
     else
     {
         roomNameInputField.transform.position = uiLobbyUp;
         joinRoomBtn.transform.position        = uiLobbyDown;
         createRoomBtn.gameObject.SetActive(false);
         joinRoomBtn.gameObject.SetActive(true);
         roomNameInputField.gameObject.SetActive(true);
         backBtn.gameObject.SetActive(true);
         lobbyText.text = "Join Room";
     }
 }
Esempio n. 30
0
        public void LeaveRoom()
        {
            SocketEvent socketEvent = new SocketEvent("LeaveRoom", "");

            string toJsonStr = JsonUtility.ToJson(socketEvent);

            ws.Send(toJsonStr);

            roomNameInputField.text = null;
            joinRoomInputField.text = null;

            roomNameInput.SetActive(false);
            joinRoomInput.SetActive(false);
            chatRoom.SetActive(false);
            lobbyRoom.SetActive(true);
            activeButtonJoinRoom.SetActive(true);
            activeButtonRoomName.SetActive(true);
            joinRoomInput.SetActive(false);
            roomNameInput.SetActive(false);
            showPopUp.SetActive(false);
        }
Esempio n. 31
0
        public void Login(string login)
        {
            if (ws.ReadyState == WebSocketState.Open)
            {
                if (InputID.text == "" || InputPassword.text == "")
                {
                    backLoginInputFail = true;
                    rootLoginInputFail.SetActive(true);
                }
                else
                {
                    login = InputID.text + "#" + InputPassword.text;

                    SocketEvent socketEvent = new SocketEvent("Login", login);

                    string toJsonStr = JsonUtility.ToJson(socketEvent);

                    ws.Send(toJsonStr);
                }
            }
        }
        public void LogginButton()
        {
            if (usernameText.text != "" || passwordText.text != "")
            {
                username = usernameText.text;
                password = passwordText.text;
                LoginEvent  LoginUser   = new LoginEvent(username, password, "");
                string      LoginStr    = JsonUtility.ToJson(LoginUser);
                SocketEvent socketEvent = new SocketEvent("Login", LoginStr);
                string      toJsonStr   = JsonUtility.ToJson(socketEvent);

                ws.Send(toJsonStr);
            }
            else
            {
                LoginError.SetActive(true);
                countDelayPopup -= Time.deltaTime;

                loginInterFace.SetActive(true);
            }
        }
Esempio n. 33
0
        protected SocketBase(Ctx parent, int threadId, int sid)
            : base(parent, threadId)
        {
            m_tag = 0xbaddecaf;
            m_ctxTerminated = false;
            m_destroyed = false;
            m_lastTsc = 0;
            m_ticks = 0;
            m_rcvMore = false;
            m_monitorSocket = null;
            m_monitorEvents = 0;

            m_options.SocketId = sid;

            m_endpoints = new Dictionary<string, Own>();
            m_pipes = new List<Pipe>();

            m_mailbox = new Mailbox("socket-" + sid);
        }
Esempio n. 34
0
 protected void StopMonitor()
 {
     if (m_monitorSocket != null)
     {
         m_monitorSocket.Close();
         m_monitorSocket = null;
         m_monitorEvents = 0;
     }
 }
Esempio n. 35
0
        public void Monitor(String addr, SocketEvent events)
        {
            if (m_ctxTerminated)
            {
                throw TerminatingException.Create();
            }

            // Support deregistering 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.Equals(Address.InProcProtocol))
            {
                throw NetMQException.Create(ErrorCode.EPROTONOSUPPORT);
            }

            // Register events to monitor
            m_monitorEvents = events;

            m_monitorSocket = Ctx.CreateSocket(ZmqSocketType.Pair);
            if (m_monitorSocket == null)
                throw NetMQException.Create(ErrorCode.EFAULT);

            // Never block context termination on pending event messages
            int linger = 0;

            try
            {
                m_monitorSocket.SetSocketOption(ZmqSocketOptions.Linger, linger);
            }
            catch (NetMQException)
            {
                StopMonitor();
                throw;
            }

            // Spawn the monitor socket endpoint
            try
            {
                m_monitorSocket.Bind(addr);
            }
            catch (NetMQException)
            {
                StopMonitor();
                throw;
            }
        }
Esempio n. 36
0
        public bool Monitor(String addr, SocketEvent events)
        {
            bool rc;
            if (m_ctxTerminated)
            {
                ZError.ErrorNumber = (ErrorNumber.ETERM);
                return false;
            }

            // Support deregistering monitoring endpoints as well
            if (addr == null)
            {
                StopMonitor();
                return true;
            }

            //  Parse addr_ string.
            //Uri uri;
            //try
            //{
            //  uri = new Uri(addr);
            //}
            //catch (UriFormatException ex)
            //{
            //  ZError.ErrorNumber = (ErrorNumber.EINVAL);
            //  throw new ArgumentException(addr, ex);
            //}
            //String protocol = uri.Scheme;
            //String address = uri.Authority;
            //String path = uri.AbsolutePath;
            //if (string.IsNullOrEmpty(address))
            //  address = path;

            string address;
            string protocol;
            DecodeAddress(addr, out address, out protocol);

            CheckProtocol(protocol);

            // Event notification only supported over inproc://
            if (!protocol.Equals("inproc"))
            {
                ZError.ErrorNumber = (ErrorNumber.EPROTONOSUPPORT);
                return false;
            }

            // Register events to monitor
            m_monitorEvents = events;

            m_monitorSocket = Ctx.CreateSocket(ZmqSocketType.Pair);
            if (m_monitorSocket == null)
                return false;

            // Never block context termination on pending event messages
            int linger = 0;
            rc = m_monitorSocket.SetSocketOption(ZmqSocketOptions.Linger, linger);
            if (!rc)
                StopMonitor();

            // Spawn the monitor socket endpoint
            rc = m_monitorSocket.Bind(addr);
            if (!rc)
                StopMonitor();
            return rc;
        }
Esempio n. 37
0
 internal static extern unsafe Error WaitForSocketEvents(int port, SocketEvent* buffer, int* count);
Esempio n. 38
0
 internal static extern unsafe Error FreeSocketEventBuffer(SocketEvent* buffer);
Esempio n. 39
0
 internal static extern unsafe Error CreateSocketEventBuffer(int count, SocketEvent** buffer);
Esempio n. 40
0
File: ZMQ.cs Progetto: knocte/netmq
        public static bool SocketMonitor(SocketBase s, String addr, SocketEvent events)
        {
            if (s == null || !s.CheckTag())
            {
                throw new InvalidOperationException();
            }

            return s.Monitor(addr, events);
        }
Esempio n. 41
0
        public void Monitor([CanBeNull] string addr, SocketEvent 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.Equals(Address.InProcProtocol))
            {
                throw new ProtocolNotSupportedException(string.Format("In SocketBase.Monitor({0},), protocol must be inproc", addr));
            }

            // Register events to monitor
            m_monitorEvents = events;

            m_monitorSocket = Ctx.CreateSocket(ZmqSocketType.Pair);
            if (m_monitorSocket == null)
                throw new FaultException("In SocketBase.Monitor, Ctx.CreateSocket(ZmqSocketType.Pair) failed.");

            // Never block context termination on pending event messages
            const int linger = 0;

            try
            {
                m_monitorSocket.SetSocketOption(ZmqSocketOptions.Linger, linger);
            }
            catch (NetMQException)
            {
                StopMonitor();
                throw;
            }

            // Spawn the monitor socket endpoint
            try
            {
                m_monitorSocket.Bind(addr);
            }
            catch (NetMQException)
            {
                StopMonitor();
                throw;
            }
        }
Esempio n. 42
0
 public MonitorEvent(SocketEvent monitorEvent, [NotNull] string addr, ErrorCode arg)
     : this(monitorEvent, addr, (int)arg)
 {
 }
Esempio n. 43
0
        public static void SocketMonitor(SocketBase s, String addr, SocketEvent events)
        {
            if (s == null || !s.CheckTag())
            {
                throw NetMQException.Create(ErrorCode.EFAULT);
            }

            s.Monitor(addr, events);
        }
Esempio n. 44
0
 public MonitorEvent(SocketEvent monitorEvent, [NotNull] string addr, AsyncSocket arg)
     : this(monitorEvent, addr, (object)arg)
 {
 }