471,357 Members | 1,046 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

[Remoting] IPAddress of connected client

KBJ
Hi,
How can I get IP address of client, which sends request to server via .net
remoting?

Regards,
Kate
Jul 18 '08 #1
3 4099
Hi Kate,
How can I get IP address of client, which sends request to server via .net
remoting?
to be honest, I just have a piece of code, but haven't had the time to
figure out how to properly use it. But that's all I found when looking
for an answer for your question.

Cheers,
Udo

Here's the code:

class ClientIPInjectorSink : BaseChannelObjectWithProperties,
IServerChannelSink
{
private IServerChannelSink nextSink;
public ClientIPInjectorSink(IServerChannelSink nextSink)
{
this.nextSink = nextSink;
}
#region IServerChannelSink Members
public Stream GetResponseStream(IServerResponseChannelSinkStack
sinkStack, object state, IMessage msg, ITransportHeaders headers)
{
return null;
}

public ServerProcessing ProcessMessage(IServerChannelSinkStack
sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream
requestStream, out IMessage responseMsg, out ITransportHeaders
responseHeaders, out Stream responseStream)
{
//get the client's ip address, and put it in the call context. This
value will be
//extracted later so we can determine the actual address of the client.
try
{
IPAddress ipAddr =
(IPAddress)requestHeaders[CommonTransportKeys.IPAddress];
CallContext.SetData("ClientIP", ipAddr);
}
catch (Exception)
{
//do nothing
}
//pushing onto stack and forwarding the call
sinkStack.Push(this, null);

ServerProcessing srvProc = nextSink.ProcessMessage(sinkStack,
requestMsg, requestHeaders, requestStream, out responseMsg, out
responseHeaders, out responseStream);
if (srvProc == ServerProcessing.Complete)
{
// TODO: - implement post processing
}
return srvProc;
}
public void AsyncProcessResponse(IServerResponseChannelSinkSta ck
sinkStack, object state, IMessage msg, ITransportHeaders headers, Stream
stream)
{
// get the client's ip address, and put it in the call context.
This value will be
// extracted later so we can determine the actual address of the
client.
try
{
IPAddress ipAddr = (IPAddress)headers[CommonTransportKeys.IPAddress];
CallContext.SetData("ClientIP", ipAddr);
}
catch (Exception)
{
//do nothing
}
//forward to stack for further processing
sinkStack.AsyncProcessResponse(msg, headers, stream);
}
public IServerChannelSink NextChannelSink
{
get { return nextSink; }
}
#endregion
}

class ClientIPInjectorSinkProvider : IServerChannelSinkProvider
{
private IServerChannelSinkProvider nextProvider;

#region IServerChannelSinkProvider Members
public IServerChannelSink CreateSink(IChannelReceiver channel)
{
//create other sinks in the chain
IServerChannelSink nextSink = nextProvider.CreateSink(channel);
return new ClientIPInjectorSink(nextSink);
}
public IServerChannelSinkProvider Next
{
get { return nextProvider; }
set { nextProvider = value; }
}
public void GetChannelData(IChannelDataStore channelData)
{
//not needed
}
#endregion
}

Jul 21 '08 #2
Just to elaborate a little on Udos response, you will need to add the
sink he provided into your remoting sink chain. Below are a couple of
articals that should explain how you use Udos code.

http://www.codeproject.com/KB/IP/chainingchannels.aspx
http://www.codeproject.com/KB/IP/Rem...hitecture.aspx
http://www.codeproject.com/KB/IP/customsinks.aspx
http://msdn.microsoft.com/en-us/libr...y3(VS.80).aspx

Cheers
Dan

On 21 Jul, 07:13, Udo Nesshoever <Brucklyn...@googlemail.comwrote:
Hi Kate,
How can I get IP address of client, which sends request to server via .net
remoting?

to be honest, I just have a piece of code, but haven't had the time to
figure out how to properly use it. But that's all I found when looking
for an answer for your question.

Cheers,
Udo

Here's the code:

class ClientIPInjectorSink : BaseChannelObjectWithProperties,
IServerChannelSink
{
* *private IServerChannelSink nextSink;
* *public ClientIPInjectorSink(IServerChannelSink nextSink)
* *{
* * *this.nextSink = nextSink;
* *}
* *#region IServerChannelSink Members
* *public Stream GetResponseStream(IServerResponseChannelSinkStack
sinkStack, object state, IMessage msg, ITransportHeaders headers)
* *{
* * *return null;
* *}

* *public ServerProcessing ProcessMessage(IServerChannelSinkStack
sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream
requestStream, out IMessage responseMsg, out ITransportHeaders
responseHeaders, out Stream responseStream)
* *{
* * *//get the client's ip address, and put it in the call context.This
value will be
* * *//extracted later so we can determine the actual address of the client.
* * *try
* * *{
* * * *IPAddress ipAddr =
(IPAddress)requestHeaders[CommonTransportKeys.IPAddress];
* * * *CallContext.SetData("ClientIP", ipAddr);
* * *}
* * *catch (Exception)
* * *{
* * * *//do nothing
* * *}
* * *//pushing onto stack and forwarding the call
* * *sinkStack.Push(this, null);

* * *ServerProcessing srvProc = nextSink.ProcessMessage(sinkStack,
requestMsg, requestHeaders, requestStream, out responseMsg, out
responseHeaders, out responseStream);
* * *if (srvProc == ServerProcessing.Complete)
* * *{
* * * *// TODO: - implement post processing
* * *}
* * *return srvProc;
* *}
* *public void AsyncProcessResponse(IServerResponseChannelSinkSta ck
sinkStack, object state, IMessage msg, ITransportHeaders headers, Stream
stream)
* *{
* * *// get the client's ip address, and put it in the call context..
This value will be
* * *// extracted later so we can determine the actual address of the
client.
* * *try
* * *{
* * * *IPAddress ipAddr = (IPAddress)headers[CommonTransportKeys.IPAddress];
* * * *CallContext.SetData("ClientIP", ipAddr);
* * *}
* * *catch (Exception)
* * *{
* * * *//do nothing
* * *}
* * *//forward to stack for further processing
* * *sinkStack.AsyncProcessResponse(msg, headers, stream);
* *}
* *public IServerChannelSink NextChannelSink
* *{
* * *get { return nextSink; }
* *}
* *#endregion

}

class ClientIPInjectorSinkProvider : IServerChannelSinkProvider
{
* *private IServerChannelSinkProvider nextProvider;

* *#region IServerChannelSinkProvider Members
* *public IServerChannelSink CreateSink(IChannelReceiver channel)
* *{
* * *//create other sinks in the chain
* * *IServerChannelSink nextSink = nextProvider.CreateSink(channel);
* * *return new ClientIPInjectorSink(nextSink);
* *}
* *public IServerChannelSinkProvider Next
* *{
* * *get { return nextProvider; }
* * *set { nextProvider = value; }
* *}
* *public void GetChannelData(IChannelDataStore channelData)
* *{
* * *//not needed
* *}
* *#endregion

}- Hide quoted text -

- Show quoted text -
Jul 21 '08 #3
=== original message ===
from: da*********@gmail.com
date: 21.07.2008 09:02
Just to elaborate a little on Udos response, you will need to add the
sink he provided into your remoting sink chain. Below are a couple of
articals that should explain how you use Udos code.

http://www.codeproject.com/KB/IP/chainingchannels.aspx
http://www.codeproject.com/KB/IP/Rem...hitecture.aspx
http://www.codeproject.com/KB/IP/customsinks.aspx
http://msdn.microsoft.com/en-us/libr...y3(VS.80).aspx
Cool, thanks. I'll check that out, too ;)

Cheers,
Udo
Jul 21 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Sunny | last post: by
4 posts views Thread by M.Perry | last post: by
1 post views Thread by Thomee Wright | last post: by
4 posts views Thread by baramuse | last post: by
1 post views Thread by Thomas René Sidor | last post: by
reply views Thread by Rich | last post: by
reply views Thread by senpark15 | last post: by
reply views Thread by XIAOLAOHU | last post: by

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.