473,401 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Socket to Browser (localhost)

Hello all!

I am trying to develop some kind of proxy which filters the data the
browser
sents to a webserver (www.google.de, www.gmx.net, ...). For this
reason I set a Proxy Connection in my IE 6.0 Settings at port 8000
(e.g) and the server to localhost (the proxy that runs local). Now I
use the TCPListener which listens and recieves data after I typed in
and pressed the send button from the browser. After this I take the
data and send it via Socket Connection to the url which was listed in
the data from the browser. Then I receieve the response content from
the webserver and want to send it back to the browser, but something
in my sourcecode isnt working right. I sitting here for days with no
idea.

Here is the code so far:

private string ConnectToURL(string server){
Socket s = null;
IPEndPoint hostEndPoint;
IPAddress hostAddress = null;
int conPort = 80;
string content="";

IPHostEntry hostInfo = Dns.Resolve(server);
IPAddress[] IPaddresses = hostInfo.AddressList;

for (int i=0; i<IPaddresses.Length; i++){
hostAddress = IPaddresses[i];
hostEndPoint = new IPEndPoint(hostAddress, conPort);

s = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp);
s.Connect(hostEndPoint);

if(s.Connected){
byte[] bytes = Encoding.ASCII.GetBytes(this.textBox1.Text);
s.Send(bytes);

while(s.Receive(bytes)>0) {
content += Encoding.ASCII.GetString(bytes);
}

s.Shutdown(SocketShutdown.Both);
s.Close();
}
}

return content;
}
while(true){
try{
/***************************/
/* get header from browser */
/***************************/

this.tcpListener.Start();
this.socketToClient = this.tcpListener.AcceptSocket();

byte[] bytes = new byte[1024];
this.socketToClient.Receive(bytes, 0,
this.socketToClient.Available, SocketFlags.None);

this.tcpListener.Stop();

string header, host;
header = Encoding.ASCII.GetString(bytes);

host = header.Substring(header.IndexOf("Host: ")+6);
host = host.Substring(0, host.IndexOf("\n"));

this.textBox1.Text = header.ToString().Trim();

/*****************************/
/* Request data from browser */
/*****************************/

string content =ConnectToURL(host.Trim());
/*****************************/
/* Send data back to browser */
/*****************************/
byte[] bytes2 = ec.GetBytes(content);
this.socketToClient.Send(bytes2);

if(this.socketToClient.Connected){
this.socketToClient.Shutdown(SocketShutdown.Both);
this.socketToClient.Close();
}
}
catch (Exception e){
MessageBox.Show(e.ToString());
}
}

thank you in advance
Nov 16 '05 #1
0 1763

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Lindstrom Greg - glinds | last post by:
Hello- I have a python routine (Python 2.2.3 on Windows 2000 "Professional") using a socket connection. Problem is, the backend service I'm connecting to will hang every so often and the socket...
3
by: Pugi! | last post by:
On a freshly installed Fedora C3 (incl. webserver apache php mysql) i get the following problem when connecting to mysql through a browser (phpMyAdmin): : #2002 Can't connect to local MySQL...
1
by: mjcast | last post by:
I have been working on an ActiveX control in C#. It is packaged in a Windows Control library and the code is in a user control. The control is used as an automation receiver that is used to update a...
3
by: Daniel | last post by:
TcpClient close() method socket leak when i use TcpClient to open a connection, send data and close the TcpClient with myTcpClientInstance.Close(); it takes 60 seconds for the actual socket on...
9
by: AA | last post by:
This is making me crazy!! Please, if some body can help me. I'm testing a ver simple socket client. In my test I just open and close a connection (in a loop) to my local IIS server (port 80)...
1
by: Laura T. | last post by:
Hi, I've this kind a program, using sockets to communicate with the clients. One of the clients can be a web browser (like IE). When using IE as a client, the transmission blocks completely, and...
8
by: Mark Fink | last post by:
I try to port a server application to Jython. At the moment I use Jython21\Lib\socket.py Currently I do face problems with casting the string "localhost" to the desired value:...
4
by: schwehr | last post by:
Hi All, I've tried to RTFM this and am having no luck. First off, I am using Mac OSX 10.4.7 with python 2.4.2 from fink. I am trying to connect to a server that should be rejecting...
0
by: palmem | last post by:
I am trying to write a simple FTP server in order to learn about sockets This is my first time trying sockets This code should take a connection on port 8110, dump it to a client "thread" (not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.