コード例 #1
0
ファイル: WebSocketServer.cs プロジェクト: danclegg/CQJSSmart
        public void Send(string message)
        {
            foreach (SocketConnection item in connectionSocketList)
            {
                if (!item.ConnectionSocket.ClientConnected(item.clientindex))
                {
                    return;
                }
                try
                {
                    if (item.IsDataMasked)
                    {
                        DataFrame dr = new DataFrame(message);
                        item.ConnectionSocket.SendData(item.clientindex, dr.GetBytes(), dr.GetBytes().Length);
                    }
                    else
                    {
                        item.ConnectionSocket.SendData(item.clientindex, FirstByte, FirstByte.Length);

                        item.ConnectionSocket.SendData(item.clientindex, Encoding.GetEncoding(28591).GetBytes(message), Encoding.GetEncoding(28591).GetBytes(message).Length);
                        item.ConnectionSocket.SendData(item.clientindex, LastByte, LastByte.Length);
                    }
                }
                catch (Exception ex)
                {
                    this.Log(string.Format("Exception:{0}", ex.Message));

                    //  logger.Log(ex.Message);
                }
            }
        }
コード例 #2
0
 public void Send(string message)
 {
     foreach (SocketConnection item in connectionSocketList)
     {
         logger.Log("发送的消息:  " + message);
         if (!item.ConnectionSocket.Connected)
         {
             return;
         }
         try
         {
             if (item.IsDataMasked)
             {
                 DataFrame dr = new DataFrame(message);
                 item.ConnectionSocket.Send(dr.GetBytes());
             }
             else
             {
                 item.ConnectionSocket.Send(FirstByte);
                 item.ConnectionSocket.Send(Encoding.UTF8.GetBytes(message));
                 item.ConnectionSocket.Send(LastByte);
             }
         }
         catch (Exception ex)
         {
             logger.Log(ex.Message);
         }
     }
 }
コード例 #3
0
 //单线发送消息
 public void SingleSend(string message, SocketConnection sconn)
 {
     if (!sconn.ConnectionSocket.Connected)
     {
         return;
     }
     try
     {
         if (sconn.IsDataMasked)
         {
             DataFrame dr = new DataFrame(message);
             sconn.ConnectionSocket.Send(dr.GetBytes());
         }
         else
         {
             sconn.ConnectionSocket.Send(FirstByte);
             sconn.ConnectionSocket.Send(Encoding.UTF8.GetBytes(message));
             sconn.ConnectionSocket.Send(LastByte);
         }
     }
     catch (Exception ex)
     {
         logger.Log(ex.Message);
     }
 }
コード例 #4
0
        public void SendSpecial(string message, SocketConnection sConn)
        {
            foreach (SocketConnection item in connectionSocketList)
            {
                if (!item.ConnectionSocket.Connected)
                {
                    return;
                }

                if (item.Name.Equals(sConn.Toname) || item.Name.Equals(sConn.Name))
                {
                    try
                    {
                        if (item.IsDataMasked)
                        {
                            DataFrame dr = new DataFrame(message);
                            item.ConnectionSocket.Send(dr.GetBytes());
                        }
                        else
                        {
                            item.ConnectionSocket.Send(FirstByte);
                            item.ConnectionSocket.Send(Encoding.UTF8.GetBytes(message));
                            item.ConnectionSocket.Send(LastByte);
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Log(ex.Message);
                    }
                }
            }
        }
コード例 #5
0
        public void inituser(SocketConnection sConn)
        {
            foreach (SocketConnection item in connectionSocketList)
            {
                if (!item.ConnectionSocket.Connected)
                {
                    return;
                }

                if (!item.Name.Equals(sConn.Name))
                {
                    try
                    {
                        if (sConn.IsDataMasked)
                        {
                            DataFrame dr = new DataFrame("+++" + item.Name);
                            sConn.ConnectionSocket.Send(dr.GetBytes());
                        }
                        else
                        {
                            sConn.ConnectionSocket.Send(FirstByte);
                            sConn.ConnectionSocket.Send(Encoding.UTF8.GetBytes("+++" + item.Name));
                            sConn.ConnectionSocket.Send(LastByte);
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Log(ex.Message);
                    }
                }
            }
        }
コード例 #6
0
 public void Send(string message)
 {
     foreach (SocketConnection item in connectionSocketList)
     {
         logger.Log("发送的消息:  " + message);
         if (!item.ConnectionSocket.Connected) return;
         try
         {
             if (item.IsDataMasked)
             {
                 DataFrame dr = new DataFrame(message);
                 item.ConnectionSocket.Send(dr.GetBytes());
             }
             else
             {
                 item.ConnectionSocket.Send(FirstByte);
                 item.ConnectionSocket.Send(Encoding.UTF8.GetBytes(message));
                 item.ConnectionSocket.Send(LastByte);
             }
         }
         catch (Exception ex)
         {
             logger.Log(ex.Message);
         }
     }
 }