S
sven22
Hi I'm programming a local proxy which should at first only be able to
pass the request to the webserver and to return the response to the
browser. But i t doesn't work!
I get problems:
1) webrequest & response
when I read in the result into a string and send the encoding in UTF8
or ASCII back to the browser (somehow images are not displayed
because some info gets lost) -using streamreader
when I read the result from the response by using bytes[] b=new
byte[1024]
stream.read(b,0, b.Length)
-> gets me only half of the page - rest is garbage - no images
displayed
that works only if I set b to 1 - which is painfully slow but
works...
2)sockets
proggie hangs at the recieve line send is ok, I get connected but I
don't recieve anything see code below
...
Uri myUri = new Uri(URL);
IPHostEntry IPHost = Dns.Resolve(myUri.Host);
Console.WriteLine("Request resolved:
{0}", IPHost.HostName);
string [] aliases = IPHost.Aliases;
IPAddress[] address = IPHost.AddressList;
Console.WriteLine(address[0]);
IPEndPoint sEndpoint = new IPEndPoint(address[0],
80);
Socket server = new Socket(AddressFamily.InterNetwork,
SocketType.Stream,ProtocolType.Tcp);
server.Connect(sEndpoint);
if(server.Connected)
Console.WriteLine("Socket connect OK");
int i;
if ((i = server.SendTo(cmsg, sEndpoint)) ==
-1)
System.Console.WriteLine("Send Error!");
byte[] RecvBytes = new byte[1024];
//HANGS HERE ON RECIEVE!
if ((i = server.Receive(RecvBytes)) ==
-1)
System.Console.WriteLine("Recieve Error!");
...
Well if someone has an idea this would be really great - this trouble
me since some days and I would be happy for help.
pass the request to the webserver and to return the response to the
browser. But i t doesn't work!
I get problems:
1) webrequest & response
when I read in the result into a string and send the encoding in UTF8
or ASCII back to the browser (somehow images are not displayed
because some info gets lost) -using streamreader
when I read the result from the response by using bytes[] b=new
byte[1024]
stream.read(b,0, b.Length)
-> gets me only half of the page - rest is garbage - no images
displayed
that works only if I set b to 1 - which is painfully slow but
works...
2)sockets
proggie hangs at the recieve line send is ok, I get connected but I
don't recieve anything see code below
...
Uri myUri = new Uri(URL);
IPHostEntry IPHost = Dns.Resolve(myUri.Host);
Console.WriteLine("Request resolved:
{0}", IPHost.HostName);
string [] aliases = IPHost.Aliases;
IPAddress[] address = IPHost.AddressList;
Console.WriteLine(address[0]);
IPEndPoint sEndpoint = new IPEndPoint(address[0],
80);
Socket server = new Socket(AddressFamily.InterNetwork,
SocketType.Stream,ProtocolType.Tcp);
server.Connect(sEndpoint);
if(server.Connected)
Console.WriteLine("Socket connect OK");
int i;
if ((i = server.SendTo(cmsg, sEndpoint)) ==
-1)
System.Console.WriteLine("Send Error!");
byte[] RecvBytes = new byte[1024];
//HANGS HERE ON RECIEVE!
if ((i = server.Receive(RecvBytes)) ==
-1)
System.Console.WriteLine("Recieve Error!");
...
Well if someone has an idea this would be really great - this trouble
me since some days and I would be happy for help.