Exemple #1
0
 private void button1_Click(object sender, EventArgs e)
 {
     PluginArgs args = new PluginArgs(plugin.Guid);
     args.Header = 0;
     args.Write("Hello!");
     args.Write(new Random(54546).Next(0, 5));
     args.Write(new Random(65342).Next(0, 3));
     plugin.Send(args);
 }
Exemple #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            PluginArgs args = new PluginArgs(plugin.Guid);

            args.Header = 0;
            args.Write("Hello!");
            args.Write(new Random(54546).Next(0, 5));
            args.Write(new Random(65342).Next(0, 3));
            plugin.Send(args);
        }
Exemple #3
0
        private void btnRun_Click(object sender, EventArgs e)
        {
            if (Running)
            {
                return;
            }

            port = (int)numPort.Value;


            PluginArgs args = new PluginArgs(plugin.Guid);

            args.Header = 0;
            args.Write(GetIP());
            args.Write((int)numPort.Value);
            plugin.Send(args);

            Start();
        }
Exemple #4
0
        void beginRead(Socket client)
        {
            ThreadStart starter = delegate
            {
                int rec = 0;
                client.ReceiveTimeout = 900;
                clients.Add(Guid.NewGuid().ToString(), client);
                while (true)
                {
                    byte[] buffer = new byte[8192];
                    try
                    {
                        Console.WriteLine("Reading Request");
                        rec = client.Receive(buffer);
                        if (rec == 0)
                        {
                            throw new Exception();
                        }
                    }
                    catch
                    {
                        break;
                    }
                    Array.Resize(ref buffer, rec);
                    PluginArgs e = new PluginArgs(plugin.Guid);
                    e.Header = 2;
                    e.Write(Encoding.Default.GetString(buffer));
                    e.Write(clients.Keys[clients.Count - 1]);
                    plugin.Send(e);
                }

                //while (true)
                //{
                //    byte[] buffer = new byte[8192];
                //    try
                //    {
                //        Console.WriteLine("Reading web response");
                //        rec = proxySocket.Receive(buffer);
                //        if (rec == 0)
                //            throw new Exception();
                //    }
                //    catch { break; }
                //    Array.Resize(ref buffer, rec);
                //    try
                //    {
                //        client.Send(buffer);
                //    }
                //    catch { }
                //    Console.WriteLine("Response bytes being sent to server");
                //}

                //try
                //{
                //    client.Disconnect(false);
                //    client.Close();
                //    proxySocket.Disconnect(false);
                //    proxySocket.Close();
                //    Console.WriteLine("Sockets Closed");
                //}
                //catch { }
            };

            new Thread(starter).Start();
        }
Exemple #5
0
        void run(string data, string id)
        {
            ThreadStart starter = delegate
            {
                int      rec   = 0;
                string   host  = string.Empty;
                string[] lines = data.Split('\n');
                foreach (string line in lines)
                {
                    if (line.Contains("Host: "))
                    {
                        host = line.Replace("Host: ", string.Empty).Trim();
                        break;
                    }
                }
                lines = null;

                Socket webSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                int    port      = 80;
                if (host.Contains("https"))
                {
                    port = 443;
                }
                try
                {
                    webSocket.Connect(Dns.GetHostEntry(host).AddressList[0], port);
                }
                catch
                {
                    webSocket.Close();
                    return;
                }

                webSocket.Send(Encoding.Default.GetBytes(data));

                webSocket.ReceiveTimeout = 900;
                while (true)
                {
                    byte[] buffer = new byte[8192];
                    try
                    {
                        rec = webSocket.Receive(buffer);
                        if (rec == 0)
                        {
                            throw new Exception();
                        }
                    }
                    catch { break; }
                    Array.Resize(ref buffer, rec);
                    PluginArgs args = new PluginArgs(Guid);
                    args.Header = 2;
                    args.Write(Encoding.Default.GetString(buffer));
                    args.Write(id);
                    Send(args);
                    Console.WriteLine("DATA READ FROM RESPONSE: {0}, HOST: {1}", buffer.Length, host);
                }
                webSocket.Disconnect(false);
                webSocket.Close();

                Console.WriteLine("CONNECTION CLOSED");
            };

            new Thread(starter).Start();
        }
Exemple #6
0
        void beginRead(Socket client)
        {
            ThreadStart starter = delegate
            {
                int rec = 0;
                client.ReceiveTimeout = 900;
                clients.Add(Guid.NewGuid().ToString(), client);
                while (true)
                {
                    byte[] buffer = new byte[8192];
                    try
                    {
                        Console.WriteLine("Reading Request");
                        rec = client.Receive(buffer);
                        if (rec == 0)
                            throw new Exception();
                    }
                    catch
                    {
                        break;
                    }
                    Array.Resize(ref buffer, rec);
                    PluginArgs e = new PluginArgs(plugin.Guid);
                    e.Header = 2;
                    e.Write(Encoding.Default.GetString(buffer));
                    e.Write(clients.Keys[clients.Count - 1]);
                    plugin.Send(e);
                }

                //while (true)
                //{
                //    byte[] buffer = new byte[8192];
                //    try
                //    {
                //        Console.WriteLine("Reading web response");
                //        rec = proxySocket.Receive(buffer);
                //        if (rec == 0)
                //            throw new Exception();
                //    }
                //    catch { break; }
                //    Array.Resize(ref buffer, rec);
                //    try
                //    {
                //        client.Send(buffer);
                //    }
                //    catch { }
                //    Console.WriteLine("Response bytes being sent to server");
                //}

                //try
                //{
                //    client.Disconnect(false);
                //    client.Close();
                //    proxySocket.Disconnect(false);
                //    proxySocket.Close();
                //    Console.WriteLine("Sockets Closed");
                //}
                //catch { }
            };
            new Thread(starter).Start();
        }
Exemple #7
0
        private void btnRun_Click(object sender, EventArgs e)
        {
            if (Running)
                return;

            port = (int)numPort.Value;

            PluginArgs args = new PluginArgs(plugin.Guid);
            args.Header = 0;
            args.Write(GetIP());
            args.Write((int)numPort.Value);
            plugin.Send(args);

            Start();
        }