Back to feature list...
Proxies and custom sockets
On this page:
SOCKS4/SOCKS5 proxy servers
To connect through SOCKET4, SOCKET4a or SOCKS5 proxy servers, set GraphClient.Proxy properties
before calling the Connect() method. Use ProxyType property to specify the proxy type:
// create client instance var client = new Rebex.Net.GraphClient(); // use SOCKS5 proxy client.Proxy.ProxyType = ProxyType.Socks5; client.Proxy.Host = proxyHost; client.Proxy.Port = proxyPort; client.Proxy.UserName = proxyUserName; // connect to the server client.Connect();
HTTP CONNECT proxy servers
To connect through a HTTP proxy server, set GraphClient.Proxy property
before calling the Connect() method. Make sure the proxy server supports HTTP CONNECT method,
and set the ProxyType property to HttpConnect:
// create client instance var client = new Rebex.Net.GraphClient(); // use HTTP CONNECT proxy client.Proxy.ProxyType = ProxyType.HttpConnect; client.Proxy.Host = proxyHost; client.Proxy.Port = proxyPort; client.Proxy.UserName = proxyUserName; client.Proxy.Password = proxyPassword; // connect to the server client.Connect();
Proxies with single sign-on
Some HTTP CONNECT proxies support NTLM authentication with single sign-on. To take advantage of this
feature, set the AuthenticationMethod property to ProxyAuthentication.Ntlm.
// create client instance var client = new Rebex.Net.GraphClient(); // use HTTP CONNECT proxy client.Proxy.ProxyType = ProxyType.HttpConnect; client.Proxy.Host = proxyHost; client.Proxy.Port = proxyPort; // use single sign-on client.Proxy.AuthenticationMethod = ProxyAuthentication.Ntlm; // connect to the server client.Connect();
SSH server as proxy
It's possible to tunnel Graph sessions through an SSH server, essentially using it as a proxy server. See SSH Tunneling for more information and sample code.
Custom transport layer - ISocket
Rebex libraries make it possible to implement a custom transport layer,
giving you full control over the network communication.
All you need to do is implement a custom ISocketFactory and
ISocket interfaces and instruct the GraphClient object to use them.
// create client instance var client = new Rebex.Net.GraphClient(); // initialize factory SimpleSocketFactory factory = new SimpleSocketFactory(); factory.SocketConnecting += factory_SocketConnecting; // use the factory client.SetSocketFactory(factory); // connect to the server client.Connect();
Custom transport layer (ISocket/ISocketFactory) implementation
/// <summary>
/// Exposes SocketConnected event which is raised
/// when a socket successfully connects to a remote end.
/// </summary>
public class SimpleSocketFactory : ISocketFactory
{
/// <summary>
/// Occurs when a socket successfully connects to a remote end.
/// </summary>
public event EventHandler SocketConnecting;
// creates custom ISocket implementation
ISocket ISocketFactory.CreateSocket()
{
return new SimpleSocket(this);
}
// raises event
private void OnSocketConnecting()
{
EventHandler h = SocketConnecting;
if (h != null)
h(this, EventArgs.Empty);
}
// simple ISocket implementation
// (core functionality is taken from ProxySocket)
private class SimpleSocket : ProxySocket, ISocket
{
// creator object
private readonly SimpleSocketFactory _factory;
public SimpleSocket(SimpleSocketFactory factory)
{
_factory = factory;
}
// connects to a server and raises SocketConnected event
void ISocket.Connect(string serverName, int serverPort)
{
_factory.OnSocketConnecting();
base.Connect(serverName, serverPort);
}
// connects to a server and raises SocketConnected event
void ISocket.Connect(EndPoint endpoint)
{
_factory.OnSocketConnecting();
base.Connect(endpoint);
}
}
}
Please note that custom communication layer and proxy support are mutually exclusive - it's not possible to use both at the same time.
Back to feature list...