/// <summary> /// Return all items in the queue for the given socket, and remove them from the queue. /// Return null if there are no enqueued items for this socket. /// </summary> /// <param name="socket"></param> /// <returns></returns> public SocketSendParameters[] DequeueAll(Socket socket, Guid currentSlide) { lock (this) { if (m_QueueList.ContainsKey(socket)) { SocketQueue sq = ((SocketQueue)m_QueueList[socket]); ArrayList l = new ArrayList(); SocketSendParameters ssp = null; while (true) { ssp = sq.Dequeue(currentSlide); if (ssp == null) { break; } l.Add(ssp); } if (l.Count == 0) { return(null); } return((SocketSendParameters[])l.ToArray(typeof(SocketSendParameters))); } } return(null); }
/// <summary> /// Get the next item from the queue which is not in the provided exclusion list. /// Return null if the queue is empty or if there are no qualifying items. /// </summary> /// <returns></returns> public SocketSendParameters Dequeue(Hashtable exclusionList, Guid currentSlide) { lock (this) { SocketQueue bestSocketQueue = null; SocketSendParameters bestMessage = null; foreach (SocketQueue sq in m_QueueList.Values) { if (((exclusionList.ContainsKey(sq.Socket)) && (((ReferenceCounter)exclusionList[sq.Socket]).IsZero)) || (!exclusionList.ContainsKey(sq.Socket))) { SocketSendParameters thisSp = sq.Peek(currentSlide); if (thisSp != null) { if (thisSp.CompareTo(bestMessage, currentSlide) < 0) { bestMessage = thisSp; bestSocketQueue = sq; } } } } if (bestSocketQueue != null) { //Trace.WriteLine("Dequeue: best message tag: " + bestMessage.Tags.SlideID.ToString() + // "; current slide=" + currentSlide.ToString() + // "; seq number=" + bestMessage.SequenceNumber.ToString(), this.GetType().ToString()); return(bestSocketQueue.Dequeue(currentSlide)); } } return(null); }
IEnumerator StartConnect() { yield return(new WaitForSeconds(1.0f)); Debug.Log("连接初始化完成"); SocketQueue.getInstance().setCallback(getConnectToServerResponse); isConnect = true; }
void Update() { float time = Time.deltaTime; if (isConnect) { SocketQueue.getInstance().tick(); } }
// Update is called once per frame void Update() { deltaTime += Time.deltaTime; if (deltaTime >= maxDeltaTime && needFlush) { flushRoomListRequest(); deltaTime = 0.0f; } SocketQueue.getInstance().tick(); }
public static SocketQueue getInstance() { if (instance == null) { instance = new SocketQueue(); instance.socket = ConnectSocket.getSocketInstance(); instance.socket.setReiviceCallback(instance.changeBytes); instance.queue = new Queue <ProtocolNetResponse>(); } return(instance); }
// Use this for initialization void Start() { socket = ConnectSocket.getSocketInstance(); SocketQueue.getInstance().setCallback(getPbcResponse); createRoomPanel = gameObject.transform.parent.Find("CreateRoomPanel").GetComponent <Transform>(); roomOwnerText = transform.Find("name").GetComponent <Text>(); roomOwner = PlayerPrefs.GetString("UserName"); roomOwnerText.text = roomOwner; organizePanelEvent = gameObject.transform.parent.Find("OrganizePanel").GetComponent <OrganizePanelEvent>(); roomPanelEvent = gameObject.transform.parent.Find("RoomPanel").GetComponent <RoomPanelEvent>(); needFlush = true; deltaTime = 0.0f; maxDeltaTime = 10f; type = transform.parent.Find("Type").GetComponent <Text>(); createRoomPanel.Find("roomName").GetComponent <InputField>().text = "123"; createRoomPanel.Find("maxManCount").GetComponent <InputField>().text = "2"; }
void Update() { if (StartNetSend) { curDeltaTime += Time.deltaTime; if (curDeltaTime >= perDeltaTime) { SendPlayerData(); curDeltaTime = 0f; } } SocketQueue.getInstance().tick(); dispatch.update(); if (UdpTick) { udpSocket.tick(); } }
/// <summary> /// Set the SequenceNumber property for the specified item, then enqueue it. /// </summary> /// <param name="sp"></param> public void Enqueue(SocketSendParameters sp) { lock (this) { sp.SequenceNumber = m_NextSequenceNumber; m_NextSequenceNumber++; if (m_QueueList.ContainsKey(sp.Socket)) { ((SocketQueue)m_QueueList[sp.Socket]).Enqueue(sp); } else { SocketQueue sq = new SocketQueue(sp.Socket); sq.Enqueue(sp); m_QueueList.Add(sp.Socket, sq); } //Trace.WriteLine("Enqueue guid=" + sp.Tags.SlideID.ToString() + "; seq =" + sp.SequenceNumber.ToString(), this.GetType().ToString()); } }
void Start() { perDeltaTime = 0.05f; curDeltaTime = 0f; StartNetSend = false; UdpTick = true; socket = ConnectSocket.getSocketInstance(); udpSocket = UDPChannel.Instance; if (!udpSocket.isInit) { udpSocket.init(); } SocketQueue.getInstance().setCallback(ReceiveResponseData); dispatch = new GameNetMessageDispatch(); dispatch.logicNetSwap = this; udpSocket.setCallback(dispatch.DispatchMessage); udpSocket.setSendCallback(dispatch.DispatchMessage); GameGlobalData.player.GetComponent <PlayerBehaviourCollector>().logicSwap = this; StartCoroutine(SendStartInfo()); }
/// <summary> /// Set the SequenceNumber property for the specified item, then enqueue it. /// </summary> /// <param name="sp"></param> public void Enqueue(SocketSendParameters sp) { lock (this) { sp.SequenceNumber = m_NextSequenceNumber; m_NextSequenceNumber++; if (m_QueueList.ContainsKey(sp.Socket)) { ((SocketQueue)m_QueueList[sp.Socket]).Enqueue(sp); } else { SocketQueue sq = new SocketQueue(sp.Socket); sq.Enqueue(sp); m_QueueList.Add(sp.Socket, sq); } //Trace.WriteLine("Enqueue guid=" + sp.Tags.SlideID.ToString() + "; seq =" + sp.SequenceNumber.ToString(), this.GetType().ToString()); } }
public InMemoryMessageQueue(IConnectionManager connectionManager) { _socketQueue = new SocketQueue(); _connectionManager = connectionManager; }