Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Net.Sockets;
- using System.Net;
- namespace proxy
- {
- class Program
- {
- static void Main(string[] args)
- {
- TcpListener server = null;
- TcpClient client = null;
- RequestBuilder requestBuilder = new RequestBuilder();
- //IDictionary<string, string> request = new Dictionary<string, string>();
- try
- {
- /*
- Int32 severPort = 443;
- IPAddress serverAddress = IPAddress.Parse("192.168.1.10");
- server = new TcpListener(serverAddress, severPort);
- server.Start();
- */
- string clientHostname = "sadistic.pl";
- Int32 clientPort = 443;
- //IPAddress clientAddress = IPAddress.Parse("216.58.209.78");
- client = new TcpClient(clientHostname, clientPort);
- // Buffer for reading data
- Byte[] bytes = new Byte[256];
- String data = null;
- string request = requestBuilder.FormHttpRequest(clientHostname);
- while (true)
- {
- //Console.WriteLine("Waiting for a connection at " + serverAddress + ":" + severPort);
- //client = server.AcceptTcpClient();
- //Console.WriteLine("Connected!");
- Console.WriteLine("Sending request");
- data = null;
- // Get a stream object for reading and writing
- NetworkStream stream = client.GetStream();
- stream.Write(Encoding.ASCII.GetBytes(request), 0, Encoding.ASCII.GetBytes(request).Length);
- int i;
- // Loop to receive all the data sent by the client.
- while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
- {
- // Translate data bytes to a ASCII string.
- data = Encoding.ASCII.GetString(bytes, 0, i);
- Console.WriteLine("Received: {0}", data);
- /*
- // Process the data sent by the client.
- data = data.ToUpper();
- byte[] msg = System.Text.Encoding.ASCII.GetBytes(data);
- // Send back a response.
- stream.Write(msg, 0, msg.Length);
- Console.WriteLine("Sent: {0}", data);
- */
- }
- // Shutdown and end connection
- Console.ReadLine();
- client.Close();
- }
- }
- catch (SocketException e)
- {
- Console.WriteLine("SocketException: {0}", e);
- }
- finally
- {
- // Stop listening for new clients.
- server.Stop();
- }
- Console.WriteLine("\nHit enter to continue...");
- Console.Read();
- }
- public static string FormHttpRequest(string address)
- {
- return "null";
- }
- public static void CreateRequest()
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement