Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Proxy server

Status
Not open for further replies.

blacky10

Programmer
Joined
May 18, 2009
Messages
1
Location
PL
I would like to create a simple Proxy Server, but I'm in trouble.
I don't know how to show page content in a web browser.
In that example a web browser recives only previously taken code (s.Receive(b)).
The code is interpreted by the web browser and that is why does not appear along with a page.


class Program
{
static void Main(string[] args)
{
Program program = new Program();
IPAddress ipAddress = IPAddress.Any;
IPEndPoint adress = new IPEndPoint(ipAddress, 8000);
TcpListener listener = new TcpListener(adress);
string message = "";
listener.Start();
Console.WriteLine("Server Proxy - start");
Console.WriteLine("Connect...");
while (true)
{
Socket s = listener.AcceptSocket();
Console.WriteLine("RemoteEndPoint: " + s.RemoteEndPoint);
byte[] b = new byte[65535];
int k = s.Receive(b);
for (int i = 0; i < k; i++)
message += Convert.ToChar(b);

Console.WriteLine("Message {0}", message);
program.sendmessage(s, message);

Console.WriteLine("\nSend to : " + s.RemoteEndPoint);
s.Close();
}
}

private void sendmessage(Socket s, string message)
{
Byte[] Buffer = new Byte[message.Length + 1];
UTF8Encoding encoding = new UTF8Encoding();
int length = encoding.GetBytes(message, 0, message.Length, Buffer, 0);
s.Send(Buffer, length, 0);
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top