C# Programming
07-31-2009, 08:11 PM
Hi,
I created a proxy that listens on a port for a requests, and then redirects them to a server. For that I created a listening socket, and a client socket that streams the data.
The problem is that the server is using Authentication (for instance NTLM, or digest) and I need to authenticate the request.
I know that I can do it in a webrequest, using CredentialCache object; something like this:
CredentialCache credCache = new CredentialCache();
if ((auth & (uint)EAuthenticationFlags.eWindows) != 0) {
credCache.Add(URL, "Negotiate", (NetworkCredential) CredentialCache.DefaultCredentials);}
webRequest.Credentials = credCache;
However, I am unsure how to do it if all I have in my hand is a socket and a stream of data. Something like this:
ClientSocket.BeginReceive(Buffer, 0, Buffer.Length, SocketFlags.None, new AsyncCallback(this.OnClientReceive), ClientSocket);
DestinationSocket.BeginReceive(RemoteBuffer, 0, RemoteBuffer.Length, SocketFlags.None, new AsyncCallback(this.OnRemoteReceive), DestinationSocket);
And the code for the callbacks OnClientReceive and OnRemoteReceive:
protected void OnClientReceive(IAsyncResult ar)
{
try
{
int Ret = ClientSocket.EndReceive(ar);
if (Ret
I created a proxy that listens on a port for a requests, and then redirects them to a server. For that I created a listening socket, and a client socket that streams the data.
The problem is that the server is using Authentication (for instance NTLM, or digest) and I need to authenticate the request.
I know that I can do it in a webrequest, using CredentialCache object; something like this:
CredentialCache credCache = new CredentialCache();
if ((auth & (uint)EAuthenticationFlags.eWindows) != 0) {
credCache.Add(URL, "Negotiate", (NetworkCredential) CredentialCache.DefaultCredentials);}
webRequest.Credentials = credCache;
However, I am unsure how to do it if all I have in my hand is a socket and a stream of data. Something like this:
ClientSocket.BeginReceive(Buffer, 0, Buffer.Length, SocketFlags.None, new AsyncCallback(this.OnClientReceive), ClientSocket);
DestinationSocket.BeginReceive(RemoteBuffer, 0, RemoteBuffer.Length, SocketFlags.None, new AsyncCallback(this.OnRemoteReceive), DestinationSocket);
And the code for the callbacks OnClientReceive and OnRemoteReceive:
protected void OnClientReceive(IAsyncResult ar)
{
try
{
int Ret = ClientSocket.EndReceive(ar);
if (Ret