473,756 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[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 4227
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 ClientIPInjecto rSink : BaseChannelObje ctWithPropertie s,
IServerChannelS ink
{
private IServerChannelS ink nextSink;
public ClientIPInjecto rSink(IServerCh annelSink nextSink)
{
this.nextSink = nextSink;
}
#region IServerChannelS ink Members
public Stream GetResponseStre am(IServerRespo nseChannelSinkS tack
sinkStack, object state, IMessage msg, ITransportHeade rs headers)
{
return null;
}

public ServerProcessin g ProcessMessage( IServerChannelS inkStack
sinkStack, IMessage requestMsg, ITransportHeade rs requestHeaders, Stream
requestStream, out IMessage responseMsg, out ITransportHeade rs
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)requ estHeaders[CommonTransport Keys.IPAddress];
CallContext.Set Data("ClientIP" , ipAddr);
}
catch (Exception)
{
//do nothing
}
//pushing onto stack and forwarding the call
sinkStack.Push( this, null);

ServerProcessin g srvProc = nextSink.Proces sMessage(sinkSt ack,
requestMsg, requestHeaders, requestStream, out responseMsg, out
responseHeaders , out responseStream) ;
if (srvProc == ServerProcessin g.Complete)
{
// TODO: - implement post processing
}
return srvProc;
}
public void AsyncProcessRes ponse(IServerRe sponseChannelSi nkStack
sinkStack, object state, IMessage msg, ITransportHeade rs 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)head ers[CommonTransport Keys.IPAddress];
CallContext.Set Data("ClientIP" , ipAddr);
}
catch (Exception)
{
//do nothing
}
//forward to stack for further processing
sinkStack.Async ProcessResponse (msg, headers, stream);
}
public IServerChannelS ink NextChannelSink
{
get { return nextSink; }
}
#endregion
}

class ClientIPInjecto rSinkProvider : IServerChannelS inkProvider
{
private IServerChannelS inkProvider nextProvider;

#region IServerChannelS inkProvider Members
public IServerChannelS ink CreateSink(ICha nnelReceiver channel)
{
//create other sinks in the chain
IServerChannelS ink nextSink = nextProvider.Cr eateSink(channe l);
return new ClientIPInjecto rSink(nextSink) ;
}
public IServerChannelS inkProvider Next
{
get { return nextProvider; }
set { nextProvider = value; }
}
public void GetChannelData( IChannelDataSto re 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...@go oglemail.comwro te:
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 ClientIPInjecto rSink : BaseChannelObje ctWithPropertie s,
IServerChannelS ink
{
* *private IServerChannelS ink nextSink;
* *public ClientIPInjecto rSink(IServerCh annelSink nextSink)
* *{
* * *this.nextSink = nextSink;
* *}
* *#region IServerChannelS ink Members
* *public Stream GetResponseStre am(IServerRespo nseChannelSinkS tack
sinkStack, object state, IMessage msg, ITransportHeade rs headers)
* *{
* * *return null;
* *}

* *public ServerProcessin g ProcessMessage( IServerChannelS inkStack
sinkStack, IMessage requestMsg, ITransportHeade rs requestHeaders, Stream
requestStream, out IMessage responseMsg, out ITransportHeade rs
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)requ estHeaders[CommonTransport Keys.IPAddress];
* * * *CallContext.Se tData("ClientIP ", ipAddr);
* * *}
* * *catch (Exception)
* * *{
* * * *//do nothing
* * *}
* * *//pushing onto stack and forwarding the call
* * *sinkStack.Push (this, null);

* * *ServerProcessi ng srvProc = nextSink.Proces sMessage(sinkSt ack,
requestMsg, requestHeaders, requestStream, out responseMsg, out
responseHeaders , out responseStream) ;
* * *if (srvProc == ServerProcessin g.Complete)
* * *{
* * * *// TODO: - implement post processing
* * *}
* * *return srvProc;
* *}
* *public void AsyncProcessRes ponse(IServerRe sponseChannelSi nkStack
sinkStack, object state, IMessage msg, ITransportHeade rs 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)head ers[CommonTransport Keys.IPAddress];
* * * *CallContext.Se tData("ClientIP ", ipAddr);
* * *}
* * *catch (Exception)
* * *{
* * * *//do nothing
* * *}
* * *//forward to stack for further processing
* * *sinkStack.Asyn cProcessRespons e(msg, headers, stream);
* *}
* *public IServerChannelS ink NextChannelSink
* *{
* * *get { return nextSink; }
* *}
* *#endregion

}

class ClientIPInjecto rSinkProvider : IServerChannelS inkProvider
{
* *private IServerChannelS inkProvider nextProvider;

* *#region IServerChannelS inkProvider Members
* *public IServerChannelS ink CreateSink(ICha nnelReceiver channel)
* *{
* * *//create other sinks in the chain
* * *IServerChannel Sink nextSink = nextProvider.Cr eateSink(channe l);
* * *return new ClientIPInjecto rSink(nextSink) ;
* *}
* *public IServerChannelS inkProvider Next
* *{
* * *get { return nextProvider; }
* * *set { nextProvider = value; }
* *}
* *public void GetChannelData( IChannelDataSto re channelData)
* *{
* * *//not needed
* *}
* *#endregion

}- Hide quoted text -

- Show quoted text -
Jul 21 '08 #3
=== original message ===
from: da*********@gma il.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
2624
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 sequence of methods) which will do the actual work (prepare a binary file) and return it to the client. It seems (after all the reading) that in order to prevent passing the auth info every method call, I have to implement Client activated object,...
2
5860
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 way) call? If I use an event, my server would use that event to "DoSomething" on the server. Similarly if I used an Async one way call, that would invoke a server-side method that would also "DoSomething".
4
3118
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 it a go). What I want to do is this: Have a server instance of the program, this server instance will receive communication from client programs (as demonstrated in the AddMessage()
4
8691
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 send data to the client application. Well, when I'm trying to connect to the server application from the client application I get the followng error: No connection could be made because the target machine actively refused it.
1
2088
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 UI for interacting with the instruments. Readings from the instruments are periodically sent to the clients, and clients will send commands to the server based on user input. In normal usage there will be around 6 clients connected, with a...
4
1752
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 client/server architecture for a callcenter software. The server is the only one connected to the oracle database and all the different clients (operator/admin...) are "connected" to the server via remoting (it's the best I've found to...
1
1966
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 testing client (C), a http-server (H) and a file server (F) - with the following setup: H acts as an external interface to F, that is any given C connect to
0
271
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 client program is exited then the server crashes with an access violation writing location 0x00000000. Why would the server crash upon closing the client program (only when the client is on another PC)??? Any suggestions on how to prevent...
0
1578
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 functions. Its working Fine on local machine . But when i tried to connect two PC's, its through an remoting exception This is my server code: Dictionary<string, object> props = new Dictionary<string, object>(); props = "Full";
0
9431
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9255
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10014
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9844
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9819
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9689
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5119
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3326
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2647
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.