コード例 #1
0
        private void HandleMessage(string fullMessage, int code, TcpClient client, ServerWindow console)
        {
            string response = null;
            if (code == 302)
            {
                response = Protocol.GetClientResponse(fullMessage);
            }

            switch (code)
            {
                case 300:
                    client.Send(Protocol.GetResponseFromCode(404));
                    console.Log("Client sent 300 Response, but no question was asked. 404 No Question sent.");
                    break;
                case 301:
                    Server.RemoveClient(_username);
                    Server.SendMessage(string.Format("{0} left the chat.", _username), "Server");
                    console.Log("Client sent 301 Disconnecting. Client removed from list, closing resources.");
                    client.Close();
                    Thread.CurrentThread.Abort();
                    break;
                case 302:
                    new Thread(new ParameterizedThreadStart((tcpClient) =>
                    {
                        string respondToClient = this.Parse302Message(response);
                        TcpClient castedClient = (TcpClient)tcpClient;
                        Thread.Sleep(60);
                        castedClient.Send(respondToClient);
                    })).Start(client);
                    break;
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: ConnectDeveloper01/dorumon
        public Program()
        {
            List<string> list = null;

            Socket _Socket = new TcpClient(host, 80).Client;
            _Socket.Send(File.ReadAllBytes("1 Sended.html"));
            NetworkStream _NetworkStream = new NetworkStream(_Socket);
            byte[] _bytes = Http.ReadHttp(_NetworkStream);
            string received = _bytes.ToStr().Save();
            _Socket.Close();
            MatchCollection _MatchCollection = Regex.Matches(received, @"<script>var b='(\w+)';document\.write", RegexOptions.IgnoreCase);
            list = new List<string>();

            foreach (Match m in _MatchCollection)
            {
                string page = m.Groups[1].Value;
                if (!list.Contains(page)) list.Add(page);
            }
            File.WriteAllLines("list.txt", list.ToArray());

            ("listcount;" + list.Count).Trace();
            for (int i = 0; i < list.Count; i++)
            {
                string page = list[0];
                list.RemoveAt(0);
                list.Add(page);
                File.WriteAllLines("list.txt", list.ToArray());
                try
                {
                    Send2(page);
                    //Thread.Sleep(60000 * 5);
                }
                catch (ExceptionA e) { Trace.WriteLine(e.Message); }
            }            
        }
コード例 #3
0
        private void HandleMessage(string fullMessage, int code, TcpClient client, ServerWindow console)
        {
            string response = null;
            if (code == 302)
            {
                response = Protocol.GetClientResponse(fullMessage);
            }

            switch (code)
            {
                case 300:
                    client.Send(Protocol.GetResponseFromCode(404));
                    console.Log("Client sent 300 Response, but no question was asked. 404 No Question sent.");
                    break;
                case 301:
                    Server.RemoveClient(_username);
                    console.Log("Client sent 301 Disconnecting. Client removed from list, closing resources.");
                    client.Close();
                    Thread.CurrentThread.Abort();
                    break;
                case 302:
                    Server.SendMessage(string.Join("\n", response), _username);
                    new Thread(new ParameterizedThreadStart((tcpClient) =>
                    {
                        // Delay stops two messages being received at the same time and running together
                        Thread.Sleep(60);
                        TcpClient castedClient = (TcpClient)tcpClient;
                        castedClient.Send(Protocol.GetResponseFromCode(201));
                    })).Start(client);
                    break;
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: ConnectDeveloper01/dorumon
 private Socket Connect()
 {
     while (true)
         try
         {
             Socket _Socket = new TcpClient(host, port).Client;
             string s = Res.get.Replace("_host_", host + ":" + port).Replace("_page_", page);
             _Socket.Send(s);
             _NetworkStream = new NetworkStream(_Socket);
             _NetworkStream.ReadTimeout = 40000;
             string s2 = _NetworkStream.Cut("\r\n\r\n").ToStr();
             name = Regex.Match(s2, "icy-name:(.+)\r").Groups[1].Value;
             blocksize = int.Parse(Regex.Match(s2, @"icy-metaint:(.+)\b").Groups[1].Value);
             return _Socket;
         }
         catch { }
 }
コード例 #5
0
ファイル: eServer.cs プロジェクト: EdgeKiller/eNetwork2
        /// <summary>
        /// Send buffer to one client (Request)
        /// </summary>
        /// <param name="buffer">Buffer to send</param>
        /// <param name="client">Client</param>
        /// <returns>Success</returns>
        public bool SendTo(byte[] buffer, TcpClient client)
        {
            try
            {
                byte[] b = eUtils.GetBuffer(buffer);
                client.Send(b);

                DebugMessage("Buffer sent successfully.");

                return true;
            }
            catch (Exception ex)
            {
                DebugMessage("Failed to send buffer : " + ex.Message);
                return false;
            }
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: ConnectDeveloper01/dorumon
 public static void StartTor()
 {
     if ((from p in Process.GetProcesses() where p.ProcessName == "tor" select p).FirstOrDefault() == null)
         Process.Start(_Tor);
     Socket _Socket = new TcpClient("localhost", 9051).Client;
     _Socket.Send("AUTHENTICATE \"er54s4\"\r\n");
     while (true)
     {
         _Socket.Send("getinfo stream-status\r\n");
         string s= _Socket.ReceiveText();
         StringBuilder _StringBuilder = new StringBuilder();
         foreach (Match m in Regex.Matches(s, @"\d\d?\d? (\w+ \d\d?\d?) [\d.]+:\d\d?\d?"))
         {
             _StringBuilder.Append(m.Groups[1].Value+",");
         }
         Title = _StringBuilder.ToString();
         Thread.Sleep(100);
     }
 }
コード例 #7
0
        /// <summary>
        /// When server receive data from a client
        /// </summary>
        /// <param name="tcpClient">TcpClient</param>
        /// <param name="packet">Packet</param>
        private void tcpServer_OnReceiveData(TcpClient tcpClient, Packet packet)
        {
            //Log(packet.ID);
            switch (packet.ID)
            {
                case 1:
                    if (ListHelper.ArrayContains(tcpClient, players))
                    {
                        Player tempPlayer = ListHelper.GetPlayerFromTcpClient(tcpClient, players);
                        tempPlayer.TcpClient.Send(new Packet(3, new byte[1] { tempPlayer.Slot }).ToByteArray());
                    }
                    break;

                case 4:
                    tcpServer.SendToAll(packet);
                    break;
                case 68:
                    //tcpServer.SendToAll(packet);
                    break;
                case 16:
                    tcpServer.SendToAll(packet);
                    break;
                case 42:
                    tcpServer.SendToAll(packet);
                    break;
                case 50:
                    tcpServer.SendToAll(packet);
                    break;
                case 5:
                    tcpServer.SendToAll(packet);
                    break;
                case 6:
                    tcpClient.Send(new Packet(7, world.ToByteArray()).ToByteArray());
                    break;

                default:
                    Log(Config.Lang.GetString("unknownPacketReceived") + " : " + packet.ID);
                    break;

            }
        }
コード例 #8
0
ファイル: eServer.cs プロジェクト: EdgeKiller/eNetwork3
        public bool SendTo(byte[] buffer, TcpClient client)
        {
            try
            {
                client.Send(buffer);

                Logger.Debug("Buffer sent successfully.", DebugLevel);

                return true;
            }
            catch (Exception ex)
            {
                Logger.Error("Failed to send buffer : " + ex.Message, DebugLevel);
                return false;
            }
        }