473,387 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 4204
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Sunny | last post by:
Hi, I have to implement client/server application. The client have to instaniate an remoting object via http and pass some auth info. If the auth is OK, the client should invoke a method (or...
2
by: wobbles | last post by:
Hi Everyone (Happy New Year!), If I have clients that want to tell the server that something has happened, what would be the difference between "remoting events" and using an asynchronous (one...
4
by: Uchiha Jax | last post by:
Hello everyone, I am a plenty silly person who is trying to learn .NET remoting through trial and error (all articles I read are going over my head at the moment (mostly) so I thought i'd give...
4
by: M.Perry | last post by:
I am trying to set up two VB.NET Applications. One to sit on the server and run and the other to sit on a client computer and connect to the server application and for the server application to...
1
by: Thomee Wright | last post by:
I'm having a problem with a pair of applications I'm developing. I have a server application which interacts with several instruments, and a client app which connects to the server and provides a...
4
by: baramuse | last post by:
Hi all, before starting I must say that I'm a remoting beginner so I certainly didn't assimilate all the tricks of remoting so please be kind ;) Now here is my interrogation: I'm working on a...
1
by: Thomas René Sidor | last post by:
Hello Having been trying to find the root of this problem for several days I now hope that you can help me. I'm implementing a distributed file system - consisting of, at the moment, a...
0
by: Rich | last post by:
I have a simple test case using a remote object. When I run with server and client on the same PC everything works fine. When I run the client on another PC, the remote object works, but when the...
0
by: senpark15 | last post by:
Hi EveryBody, I am developing .net remoting application.I have Created server and client application. Server has installed on Two Pc's and cliient have to connect two Pc's and do some...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...

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.