private void timer2_Tick(object sender, EventArgs e)
        {
            ChatServerTypes.hTTPCW.ReportClients();
            string sTime = InboundMessageParser.GetSetDivString("*", "ActiveUsersDiv", DateTime.Now.ToLongTimeString());

            ChatServerTypes.hTTPCW.SendToAll(sTime);
        }
示例#2
0
        public void AddToDiv(string sDiv, string sData)
        {
            string s = InboundMessageParser.GetAddToDivString(SSIDws, sDiv, sData);

            AddToWriteList(Encoding.ASCII.GetBytes(s));
        }
示例#3
0
        async public void DoWSServeSocket(WSServerTaskAndOject wssto)
        {
            CancellationToken       ct  = wssto.ct;
            CancellationTokenSource cts = wssto.wsCts;

            NSXUserObj.sIP           = hlcIO.Request.RemoteEndPoint.Address.ToString();
            NSXUserObj.sUserAgent    = hlcIO.Request.UserAgent;
            NSXUserObj.DateStarted   = DateTime.Now;
            NSXUserObj.DateOfLastMsg = DateTime.Now;
            try
            {
                //hlcIO.Response.SendChunked = true;
                wsc = await hlcIO.AcceptWebSocketAsync("Neals");
            }
            catch (WebSocketException we)
            {
                isOKReading = false; IsNeeded = false;
                return;
            }
            WebSocketReceiveResult wr = null;

            while (isOKReading && !ct.IsCancellationRequested)
            {
                byte[] bWsIn = new byte[1024];

                try
                {
                    wr = await wsc.WebSocket.ReceiveAsync(new ArraySegment <byte>(bWsIn), wsso.ct);
                }
                catch
                {
                    isOKReading = false; IsNeeded = false;
                    cts.Cancel();
                    wssto.wsioh.Dispose();
                    IsNeeded = false;
                    ctsServerThread.Cancel();
                    wssto.wsioh.Dispose();
                    return;
                }
                if (wr.MessageType == WebSocketMessageType.Close)
                {
                    isOKReading = false; IsNeeded = false;
                }
                if (wr.MessageType == WebSocketMessageType.Text)
                {
////                    ChatServerTypes.UpdateTextSafe(ParentCW.Frm.textBox1, "Starting Server \r\n");

                    string sIN = Encoding.ASCII.GetString(bWsIn, 0, wr.Count);
                    //ChatServerTypes.UpdateTextSafe(ParentCW.Frm.textBox1, sIN + "\r\n");
                    string sHeads = "<textarea style=\"height:200px; width:200px;\">";

                    foreach (string hrh in hlcIO.Request.Headers)
                    {
                        sHeads += hrh + "\\" + hlcIO.Request.Headers[hrh] + "\r\n";
                    }
                    sHeads += "</textarea>\r\n";
                    bInBuff = null;

                    byte[] b = Encoding.ASCII.GetBytes(sHeads);

                    //int iLen; int iExtras;
                    //Int32[] b32 = StringByteInt.BytesToInt32s(b, out iLen, out iExtras);
                    //StringByteInt.minusFromAll(ref b32, 127);

                    //StringByteInt.plusToAll(ref b32, 127);

                    //b = StringByteInt.Int32sToBytes(b32, iLen, iExtras);
                    string sss = Encoding.ASCII.GetString(b, 0, b.Count());
                    bool   isBroadcast; bool isToSend;

                    string sData = sIN.Substring(0, sIN.IndexOf("</data>"));
                    sData = sData.Substring(sData.IndexOf("<data>") + 6);

                    string sid = sIN.Substring(sIN.IndexOf("<sid>") + 5).ToLower();
                    sid = sid.Substring(0, sid.IndexOf("</sid>")).ToLower();

                    sID = sid;
                    try
                    {
                        SessionInfo = SessionDataHandler.SessionDataList[sid];
                    }
                    catch { SessionInfo = new WebSessionClass(); }

                    //ChatServerTypes.UpdateTextSafe(ChatServerTypes.UiForm.textBox1, "Session not matching on WS request!");

                    InboundMessageParser.InterpreterResponse[] sRet = InboundMessageParser.InterpretCommands(sID, sData, ref SessionInfo);
                    foreach (InboundMessageParser.InterpreterResponse irMSG in sRet)
                    {
                        if (irMSG.IsToSEnd && irMSG.SResponse != "")
                        {
                            if (irMSG.IsRoomCast)
                            {
                                ParentCW.SendToRoom(irMSG.sRoomTo, irMSG.SResponse);
                            }
                            else if (irMSG.IsBroadcast)
                            {
                                ParentCW.SendToAll(irMSG.SResponse);
                            }
                            else
                            {
                                AddToWriteList(Encoding.ASCII.GetBytes(irMSG.SResponse));
                            }
                        }
                    }
                    //t = Task.Run(() => DoSomeWork(1, token), token);
                }
            }
            ctsServerThread.Cancel();
            wssto.wsioh.Dispose();


            string s = ctsServerThread.Token.CanBeCanceled.ToString();
        }