473,796 Members | 2,573 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(st ring server){
Socket s = null;
IPEndPoint hostEndPoint;
IPAddress hostAddress = null;
int conPort = 80;
string content="";

IPHostEntry hostInfo = Dns.Resolve(ser ver);
IPAddress[] IPaddresses = hostInfo.Addres sList;

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

s = new Socket(AddressF amily.InterNetw ork, SocketType.Stre am,
ProtocolType.Tc p);
s.Connect(hostE ndPoint);

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

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

s.Shutdown(Sock etShutdown.Both );
s.Close();
}
}

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

this.tcpListene r.Start();
this.socketToCl ient = this.tcpListene r.AcceptSocket( );

byte[] bytes = new byte[1024];
this.socketToCl ient.Receive(by tes, 0,
this.socketToCl ient.Available, SocketFlags.Non e);

this.tcpListene r.Stop();

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

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

this.textBox1.T ext = header.ToString ().Trim();

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

string content =ConnectToURL(h ost.Trim());
/*************** **************/
/* Send data back to browser */
/*************** **************/
byte[] bytes2 = ec.GetBytes(con tent);
this.socketToCl ient.Send(bytes 2);

if(this.socketT oClient.Connect ed){
this.socketToCl ient.Shutdown(S ocketShutdown.B oth);
this.socketToCl ient.Close();
}
}
catch (Exception e){
MessageBox.Show (e.ToString());
}
}

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

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

Similar topics

2
1828
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 will simply wait for a response which will never come. I'm thinking of putting in a routine to check the socket's status, which now brings in threading. Before I go to the trouble I thought I'd ask if there is a simple way to verify my socket...
3
17812
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 server through socket /var/lib/mysql/mysql.sock On the website of MySQL this error is mentioned but I found no solution. In /var/log/messages the following log occurs :
1
3055
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 page dynamically through the use of event listeners in javascript That works, the problem is that when I run the test webpage that runs the ActiveX control, the socket does not start listening for about a minute and a half, after which it runs fine....
3
9114
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 the client machine to close per my network app the computer fills up w/ thousands of these :0 TCP foobox:8888 localhost:2188 TIME_WAIT :0 TCP foobox:8888 localhost:2189 TIME_WAIT :0 TCP foobox:8888 localhost:2190 TIME_WAIT
9
11347
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) using System.Net.Sockets;
1
2161
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 IE times out after a long time while stating opening from http://localhost:7765... I have a main thread that starts TCPListener and listens and accepts the connection and queues a worker thread to handle the socket transmission:
8
6006
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: D:\AUT_TEST\workspace\JyFIT>jython fit/JyFitServer2.py localhost 1234 23 localhost Traceback (innermost last): File "fit/JyFitServer2.py", line 146, in ?
4
5232
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 connections and I was surprised when it did not throw an exception or do something otherwise equally nasty. It just connects and never returns any data. First, the proof that something is there and rejecting the connection (or is it that this thing...
0
4623
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 a thread yet), print "Test\n" to the thread, and close everything. It fails on creating the client thread with error 106: 'Transport endpoint is already connected'
0
9684
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10459
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10236
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10182
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6793
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5445
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5577
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4120
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2928
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.