The code of classes given below is for server to which clients connect
i want to get ip address of client which has connected
pls help how can i get
//listen class
public class listen
{
TcpListener server=null;
Thread tcpthread=null;
client[] cl=new client[3];
public listen()
{
//
// TODO: Add constructor logic here
//
}
public void startlisten()
{
Int32 port = 3310;
IPAddress localAddr = IPAddress.Parse("192.168.0.6");
// TcpListener server = new TcpListener(port);
server = new TcpListener(localAddr, port);
// Start listening for client requests.
server.Start();
// Enter the listening loop.
for(int i=0;i<3;i++)
{
cl[i]=new client();
cl[i].status=true;
}
Boolean flag;
while(true)
{
try
{
flag=false;
// Perform a blocking call to accept requests.
// You could also user server.AcceptSocket() here.
for(int i=0;i<3;i++)
{
if(cl[i].status==true)
{
cl[i]= new client(server.AcceptTcpClient());
tcpthread=new Thread(new ThreadStart(cl[i].getClient));
tcpthread.Start();
flag=true;
break;
}
}
if(flag!=true)
{
//MessageBox.Show("All Clients Busy");
}
}
catch(Exception se)
{
}
}
}
public void stoplisten()
{
server.Stop();
}
}
//client class
public class client
{
TcpClient tcpClient;
public Boolean status;
// Buffer for reading data
Byte[] bytes = new Byte[256];
String data = null;
IPAddress localAddr = IPAddress.Parse("192.168.0.6");
public client()
{ //
// TODO: Add constructor logic here
//
//status=true;
}
public client(TcpClient Client)
{
tcpClient =Client;
//
// TODO: Add constructor logic here
//
status=false;
}
public void getClient()
{
try
{
data = null;
// Get a stream object for reading and writing
NetworkStream stream = tcpClient.GetStream();
int i;
// Loop to receive all the data sent by the client.
while((i = stream.Read(bytes, 0, bytes.Length))!=0)
{
// Translate data bytes to a ASCII string.
data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
// Process the data sent by the client.
string replyMsg = data;
clamdCommand x=new clamdCommand();
replyMsg=x.Command(replyMsg);
int
lowerport=int.Parse(ConfigurationSettings.AppSetti ngs.Get("lowerport"));
int
upperport=int.Parse(ConfigurationSettings.AppSetti ngs.Get("upperport"));
for(int y=lowerport;y<upperport;y++)
{
if(replyMsg==y.ToString())
{
replyMsg=replyMsg+"\r\n\0";
byte[] msg = System.Text.Encoding.ASCII.GetBytes(replyMsg);
// Send back a response.
stream.Write(msg, 0, msg.Length);
TcpListener listener=new TcpListener(localAddr,y);
listener.Start();
// Buffer for reading data
Byte[] bs = new Byte[256];
String ds = null;
// Enter the listening loop.
while(true)
{ // Perform a blocking call to accept requests.
// You could also user server.AcceptSocket() here.
TcpClient bufferclient = listener.AcceptTcpClient();
ds = null;
// Get a stream object for reading and writing
NetworkStream strm = bufferclient.GetStream();
int l;
// Loop to receive all the data sent by the client.
while((l = strm.Read(bs, 0, bs.Length))!=0)
{ ds = System.Text.Encoding.ASCII.GetString(bs, 0, l);
// Process the data sent by the client.
clamresults obj=new clamresults();
ds=obj.loadDatabase("STREAM",ds);
replyMsg=ds;
bufferclient.Close();
break;
}
listener.Stop();
x.freeport(y-lowerport);
break;
} break;
}
}
replyMsg=replyMsg+"\r\n\0";
byte[] msgs = System.Text.Encoding.ASCII.GetBytes(replyMsg);
// Send back a response.
stream.Write(msgs, 0, msgs.Length);
}
}
catch(Exception se)
{
MessageBox.Show(se.ToString());
}
// Shutdown and end connection
finally
{
tcpClient.Close();
status=true;
}
}
} 14 4417
will it give ip address of client
i want to fetch ip address on server of client which is accepted or
connected
"Marko Becirevic" <ma*****************@inMail24.com> wrote in message
news:dq**********@sunce.iskon.hr... DNS.Resolve()
"Ankit Aneja" <ef*****@newsgroups.nospam> wrote in message
news:Oz**************@TK2MSFTNGP15.phx.gbl... will it give ip address of client i want to fetch ip address on server of client which is accepted or connected
....
No, it won't. I can't find anything in TcpClient documentation (fw 1.1)
class that would reveal client's IP address (but I may be wrong here) . If
you can use Socket class, then you can use RemoteEndPoint property.
Regards,
Goran
No, it won't. I can't find anything in TcpClient documentation (fw 1.1)
class that would reveal client's IP address (but I may be wrong here)
can i get it using framework 2.0
pls help
"Goran Sliskovic" <gs******@yahoo.com> wrote in message
news:e0**************@TK2MSFTNGP10.phx.gbl... "Ankit Aneja" <ef*****@newsgroups.nospam> wrote in message news:Oz**************@TK2MSFTNGP15.phx.gbl... will it give ip address of client i want to fetch ip address on server of client which is accepted or connected ...
No, it won't. I can't find anything in TcpClient documentation (fw 1.1) class that would reveal client's IP address (but I may be wrong here) . If you can use Socket class, then you can use RemoteEndPoint property.
Regards, Goran
can i get remote endpoint in TcpClient if i use framework2.0
"Goran Sliskovic" <gs******@yahoo.com> wrote in message
news:e0**************@TK2MSFTNGP10.phx.gbl... "Ankit Aneja" <ef*****@newsgroups.nospam> wrote in message news:Oz**************@TK2MSFTNGP15.phx.gbl... will it give ip address of client i want to fetch ip address on server of client which is accepted or connected ...
No, it won't. I can't find anything in TcpClient documentation (fw 1.1) class that would reveal client's IP address (but I may be wrong here) . If you can use Socket class, then you can use RemoteEndPoint property.
Regards, Goran
Hi Ankit,
In this current situation, I suggest you could try to invoke getpeername /
getsockname using PInvoke mechanism. On a connected socket, getpeername
will give you the remote address and getsockname will give you the local
address for the connection. We could use Socket.Handle Property to get the
socket handle and pass it into these API as parameters.
I hope the above inforamtion is helpful for you.If you have any questions
or concerns, please let me know. Thanks again and have a nice day!
Best Regards,
Terry Fei[MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Best Regards,
-------------------- From: "Ankit Aneja" <ef*****@newsgroups.nospam> References: <uq**************@TK2MSFTNGP14.phx.gbl>
<dq**********@sunce.iskon.hr> <Oz**************@TK2MSFTNGP15.phx.gbl>
<e0**************@TK2MSFTNGP10.phx.gbl>Subject: Re: getting client ip in sock-client on server Date: Thu, 19 Jan 2006 19:18:12 +0530 Lines: 30 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original Message-ID: <Ox**************@TK2MSFTNGP09.phx.gbl> Newsgroups: microsoft.public.dotnet.languages.csharp NNTP-Posting-Host: dsl-del-dynamic-067.85.246.61.touchtelindia.net
61.246.85.67Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP09.phx.gbl Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.languages.csharp:379684 X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
No, it won't. I can't find anything in TcpClient documentation (fw 1.1) class that would reveal client's IP address (but I may be wrong here)
can i get it using framework 2.0 pls help
"Goran Sliskovic" <gs******@yahoo.com> wrote in message news:e0**************@TK2MSFTNGP10.phx.gbl... "Ankit Aneja" <ef*****@newsgroups.nospam> wrote in message news:Oz**************@TK2MSFTNGP15.phx.gbl... will it give ip address of client i want to fetch ip address on server of client which is accepted or connected ...
No, it won't. I can't find anything in TcpClient documentation (fw 1.1) class that would reveal client's IP address (but I may be wrong here) .
If you can use Socket class, then you can use RemoteEndPoint property.
Regards, Goran
is there anything in framework 2.0
to get the remote address
""TerryFei"" <v-******@online.microsoft.com> wrote in message
news:9G**************@TK2MSFTNGXA02.phx.gbl... Hi Ankit,
In this current situation, I suggest you could try to invoke getpeername / getsockname using PInvoke mechanism. On a connected socket, getpeername will give you the remote address and getsockname will give you the local address for the connection. We could use Socket.Handle Property to get the socket handle and pass it into these API as parameters.
I hope the above inforamtion is helpful for you.If you have any questions or concerns, please let me know. Thanks again and have a nice day!
Best Regards,
Terry Fei[MSFT] Microsoft Community Support Get Secure! www.microsoft.com/security (This posting is provided "AS IS", with no warranties, and confers no rights.) Best Regards,
--------------------From: "Ankit Aneja" <ef*****@newsgroups.nospam> References: <uq**************@TK2MSFTNGP14.phx.gbl> <dq**********@sunce.iskon.hr> <Oz**************@TK2MSFTNGP15.phx.gbl> <e0**************@TK2MSFTNGP10.phx.gbl>Subject: Re: getting client ip in sock-client on server Date: Thu, 19 Jan 2006 19:18:12 +0530 Lines: 30 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original Message-ID: <Ox**************@TK2MSFTNGP09.phx.gbl> Newsgroups: microsoft.public.dotnet.languages.csharp NNTP-Posting-Host: dsl-del-dynamic-067.85.246.61.touchtelindia.net 61.246.85.67Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP09.phx.gbl Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.languages.csharp:37968 4 X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
No, it won't. I can't find anything in TcpClient documentation (fw 1.1) class that would reveal client's IP address (but I may be wrong here)
can i get it using framework 2.0 pls help
"Goran Sliskovic" <gs******@yahoo.com> wrote in message news:e0**************@TK2MSFTNGP10.phx.gbl... "Ankit Aneja" <ef*****@newsgroups.nospam> wrote in message news:Oz**************@TK2MSFTNGP15.phx.gbl... will it give ip address of client i want to fetch ip address on server of client which is accepted or connected ...
No, it won't. I can't find anything in TcpClient documentation (fw 1.1) class that would reveal client's IP address (but I may be wrong here) . If you can use Socket class, then you can use RemoteEndPoint property.
Regards, Goran
Hi Ankit,
Thanks for your quick response! is there anything in framework 2.0 to get the remote address?
Based on my knowledge, there is no this feature in framework 2.0. But I'll
consult this question for the relevant team. If I have an easier way to
achieve this goal later, I'll inform of you as soon as possible.
Thanks for your understanding!
Best Regards,
Terry Fei[MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------From: "Ankit Aneja" <ef*****@newsgroups.nospam> References: <uq**************@TK2MSFTNGP14.phx.gbl>
<dq**********@sunce.iskon.hr> <Oz**************@TK2MSFTNGP15.phx.gbl>
<e0**************@TK2MSFTNGP10.phx.gbl>
<Ox**************@TK2MSFTNGP09.phx.gbl>
<9G**************@TK2MSFTNGXA02.phx.gbl>Subject: Re: getting client ip in sock-client on server Date: Fri, 20 Jan 2006 10:47:03 +0530 Lines: 81 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original Message-ID: <uA*************@tk2msftngp13.phx.gbl> Newsgroups: microsoft.public.dotnet.languages.csharp NNTP-Posting-Host: dsl-del-dynamic-130.84.246.61.touchtelindia.net
61.246.84.130Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msft ngp13.phx.gbl Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.languages.csharp:379924 X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
is there anything in framework 2.0 to get the remote address ""TerryFei"" <v-******@online.microsoft.com> wrote in message news:9G**************@TK2MSFTNGXA02.phx.gbl... Hi Ankit,
In this current situation, I suggest you could try to invoke getpeername
/ getsockname using PInvoke mechanism. On a connected socket, getpeername will give you the remote address and getsockname will give you the local address for the connection. We could use Socket.Handle Property to get
the socket handle and pass it into these API as parameters.
I hope the above inforamtion is helpful for you.If you have any questions or concerns, please let me know. Thanks again and have a nice day!
Best Regards,
Terry Fei[MSFT] Microsoft Community Support Get Secure! www.microsoft.com/security (This posting is provided "AS IS", with no warranties, and confers no rights.) Best Regards,
--------------------From: "Ankit Aneja" <ef*****@newsgroups.nospam> References: <uq**************@TK2MSFTNGP14.phx.gbl> <dq**********@sunce.iskon.hr> <Oz**************@TK2MSFTNGP15.phx.gbl> <e0**************@TK2MSFTNGP10.phx.gbl>Subject: Re: getting client ip in sock-client on server Date: Thu, 19 Jan 2006 19:18:12 +0530 Lines: 30 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original Message-ID: <Ox**************@TK2MSFTNGP09.phx.gbl> Newsgroups: microsoft.public.dotnet.languages.csharp NNTP-Posting-Host: dsl-del-dynamic-067.85.246.61.touchtelindia.net 61.246.85.67Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP09.phx.gbl Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.languages.csharp:3796 84 X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
No, it won't. I can't find anything in TcpClient documentation (fw 1.1) class that would reveal client's IP address (but I may be wrong here)
can i get it using framework 2.0 pls help
"Goran Sliskovic" <gs******@yahoo.com> wrote in message news:e0**************@TK2MSFTNGP10.phx.gbl...
"Ankit Aneja" <ef*****@newsgroups.nospam> wrote in message news:Oz**************@TK2MSFTNGP15.phx.gbl... > will it give ip address of client > i want to fetch ip address on server of client which is accepted or > connected ...
No, it won't. I can't find anything in TcpClient documentation (fw 1.1) class that would reveal client's IP address (but I may be wrong here) . If you can use Socket class, then you can use RemoteEndPoint property.
Regards, Goran
Thanks Sir
will wait for your reply
""TerryFei"" <v-******@online.microsoft.com> wrote in message
news:7Q**************@TK2MSFTNGXA02.phx.gbl... Hi Ankit, Thanks for your quick response!
is there anything in framework 2.0 to get the remote address? Based on my knowledge, there is no this feature in framework 2.0. But I'll consult this question for the relevant team. If I have an easier way to achieve this goal later, I'll inform of you as soon as possible. Thanks for your understanding!
Best Regards,
Terry Fei[MSFT] Microsoft Community Support Get Secure! www.microsoft.com/security (This posting is provided "AS IS", with no warranties, and confers no rights.)
--------------------From: "Ankit Aneja" <ef*****@newsgroups.nospam> References: <uq**************@TK2MSFTNGP14.phx.gbl> <dq**********@sunce.iskon.hr> <Oz**************@TK2MSFTNGP15.phx.gbl> <e0**************@TK2MSFTNGP10.phx.gbl> <Ox**************@TK2MSFTNGP09.phx.gbl> <9G**************@TK2MSFTNGXA02.phx.gbl>Subject: Re: getting client ip in sock-client on server Date: Fri, 20 Jan 2006 10:47:03 +0530 Lines: 81 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original Message-ID: <uA*************@tk2msftngp13.phx.gbl> Newsgroups: microsoft.public.dotnet.languages.csharp NNTP-Posting-Host: dsl-del-dynamic-130.84.246.61.touchtelindia.net 61.246.84.130Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msft ngp13.phx.gbl Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.languages.csharp:37992 4 X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
is there anything in framework 2.0 to get the remote address ""TerryFei"" <v-******@online.microsoft.com> wrote in message news:9G**************@TK2MSFTNGXA02.phx.gbl... Hi Ankit,
In this current situation, I suggest you could try to invoke getpeername / getsockname using PInvoke mechanism. On a connected socket, getpeername will give you the remote address and getsockname will give you the local address for the connection. We could use Socket.Handle Property to get the socket handle and pass it into these API as parameters.
I hope the above inforamtion is helpful for you.If you have any questions or concerns, please let me know. Thanks again and have a nice day!
Best Regards,
Terry Fei[MSFT] Microsoft Community Support Get Secure! www.microsoft.com/security (This posting is provided "AS IS", with no warranties, and confers no rights.) Best Regards,
-------------------- From: "Ankit Aneja" <ef*****@newsgroups.nospam> References: <uq**************@TK2MSFTNGP14.phx.gbl> <dq**********@sunce.iskon.hr> <Oz**************@TK2MSFTNGP15.phx.gbl> <e0**************@TK2MSFTNGP10.phx.gbl> Subject: Re: getting client ip in sock-client on server Date: Thu, 19 Jan 2006 19:18:12 +0530 Lines: 30 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original Message-ID: <Ox**************@TK2MSFTNGP09.phx.gbl> Newsgroups: microsoft.public.dotnet.languages.csharp NNTP-Posting-Host: dsl-del-dynamic-067.85.246.61.touchtelindia.net 61.246.85.67 Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP09.phx.gbl Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.languages.csharp:37968 4 X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
No, it won't. I can't find anything in TcpClient documentation (fw 1.1) class that would reveal client's IP address (but I may be wrong here)
can i get it using framework 2.0 pls help
"Goran Sliskovic" <gs******@yahoo.com> wrote in message news:e0**************@TK2MSFTNGP10.phx.gbl.. . > > "Ankit Aneja" <ef*****@newsgroups.nospam> wrote in message > news:Oz**************@TK2MSFTNGP15.phx.gbl... >> will it give ip address of client >> i want to fetch ip address on server of client which is accepted or >> connected > ... > > No, it won't. I can't find anything in TcpClient documentation (fw > 1.1) > class that would reveal client's IP address (but I may be wrong here) > . If > you can use Socket class, then you can use RemoteEndPoint property. > > Regards, > Goran > >
""TerryFei"" <v-******@online.microsoft.com> wrote in message
news:9G**************@TK2MSFTNGXA02.phx.gbl... Hi Ankit,
In this current situation, I suggest you could try to invoke getpeername / getsockname using PInvoke mechanism. On a connected socket, getpeername will give you the remote address and getsockname will give you the local address for the connection. We could use Socket.Handle Property to get the socket handle and pass it into these API as parameters.
I hope the above inforamtion is helpful for you.If you have any questions or concerns, please let me know. Thanks again and have a nice day!
....
The problem is that TcpClient does not expose underlying socket. Socket
TcpClient.Client is protected property (holds underlying socket). I suspect
OP could get this using reflection (I heard this is possible using
reflection, but haven't tried it myself and it is bad practice to do this of
course). Socket has RemoteEndPoint property, so it should not be needed to
PInvoke. Haven't tested it, though. Or maybe I missed the original problem?
Regards,
Goran
can u give me some sample code
how i can get remote ip without changing much of my present code
"Goran Sliskovic" <gs******@yahoo.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl... ""TerryFei"" <v-******@online.microsoft.com> wrote in message news:9G**************@TK2MSFTNGXA02.phx.gbl... Hi Ankit,
In this current situation, I suggest you could try to invoke getpeername / getsockname using PInvoke mechanism. On a connected socket, getpeername will give you the remote address and getsockname will give you the local address for the connection. We could use Socket.Handle Property to get the socket handle and pass it into these API as parameters.
I hope the above inforamtion is helpful for you.If you have any questions or concerns, please let me know. Thanks again and have a nice day!
...
The problem is that TcpClient does not expose underlying socket. Socket TcpClient.Client is protected property (holds underlying socket). I suspect OP could get this using reflection (I heard this is possible using reflection, but haven't tried it myself and it is bad practice to do this of course). Socket has RemoteEndPoint property, so it should not be needed to PInvoke. Haven't tested it, though. Or maybe I missed the original problem?
Regards, Goran
"Ankit Aneja" <ef*****@newsgroups.nospam> wrote in message
news:eb**************@TK2MSFTNGP14.phx.gbl... can u give me some sample code how i can get remote ip without changing much of my present code
....
Hi,
Here it is:
<CUT>
using System;
using System.Reflection;
using System.Reflection.Emit;
using System.Net;
using System.Net.Sockets;
namespace ConsoleApplication1 {
public class Test {
public static void Main() {
TcpListener tcpListener = new TcpListener(IPAddress.Any, 10000);
tcpListener.Start();
TcpClient client = tcpListener.AcceptTcpClient();
Type tcpClientType = typeof(TcpClient);
//get value of protected TCPClient property Client that holds
socket...
Socket clientSocket =
(Socket)tcpClientType.InvokeMember("Client", BindingFlags.GetProperty |
BindingFlags.NonPublic | BindingFlags.Instance , null, client, null);
//socket RemoteEndpoint is address of connected tcpClinet...
IPEndPoint endPoint = (IPEndPoint) clientSocket.RemoteEndPoint;
string remotAddr = endPoint.Address.ToString();
}
}
}
</CUT>
Please note that such thing is considered bad practice and potentialy
dangerous. No guarantees.
Regards,
Goran
Hi Goran, Socket has RemoteEndPoint property, so it should not be needed to PInvoke. Haven't tested it
Thanks for your reply! Yes, Socket has RemoteEndPoint property and we could
access relevant address with it in theory. However customer has tried it
and failed. So I suggest use PInvoke to achieve this goal.
Best Regards,
Terry Fei[MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------From: "Goran Sliskovic" <gs******@yahoo.com> References: <uq**************@TK2MSFTNGP14.phx.gbl>
<dq**********@sunce.iskon.hr> <Oz**************@TK2MSFTNGP15.phx.gbl>
<e0**************@TK2MSFTNGP10.phx.gbl>
<Ox**************@TK2MSFTNGP09.phx.gbl>
<9G**************@TK2MSFTNGXA02.phx.gbl>Subject: Re: getting client ip in sock-client on server Date: Fri, 20 Jan 2006 14:03:53 +0100 Lines: 27 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1506 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506 Message-ID: <#q*************@tk2msftngp13.phx.gbl> Newsgroups: microsoft.public.dotnet.languages.csharp NNTP-Posting-Host: 194-152-209-27.adsl.net.t-com.hr 194.152.209.27 Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msft ngp13.phx.gbl Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.languages.csharp:379994 X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
""TerryFei"" <v-******@online.microsoft.com> wrote in message news:9G**************@TK2MSFTNGXA02.phx.gbl... Hi Ankit,
In this current situation, I suggest you could try to invoke getpeername
/ getsockname using PInvoke mechanism. On a connected socket, getpeername will give you the remote address and getsockname will give you the local address for the connection. We could use Socket.Handle Property to get
the socket handle and pass it into these API as parameters.
I hope the above inforamtion is helpful for you.If you have any questions or concerns, please let me know. Thanks again and have a nice day!
...
The problem is that TcpClient does not expose underlying socket. Socket TcpClient.Client is protected property (holds underlying socket). I suspect OP could get this using reflection (I heard this is possible using reflection, but haven't tried it myself and it is bad practice to do this
ofcourse). Socket has RemoteEndPoint property, so it should not be needed to PInvoke. Haven't tested it, though. Or maybe I missed the original problem?
Regards, Goran
""TerryFei"" <v-******@online.microsoft.com> wrote in message
news:3n****************@TK2MSFTNGXA02.phx.gbl... Hi Goran, Socket has RemoteEndPoint property, so it should not be needed to PInvoke. Haven't tested it Thanks for your reply! Yes, Socket has RemoteEndPoint property and we
could access relevant address with it in theory. However customer has tried it and failed. So I suggest use PInvoke to achieve this goal.
....
Hi,
I posted example with tcpclient/remoteendpoint that works (no my lan),
framework 1.1. Though I can guess there may be problems in non-trivial
network setups (NAT for example).
Regards,
Goran This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: MJL |
last post by:
This is a mysql/php question (but a little more on the mysql side.)
The two are so closely related these days, I thought it would be ok to
ask here.
I installed on my Suse Linux system mysql 4.0...
|
by: Oliver Etzel - GoodnGo.COM |
last post by:
Hello all,
after Installing mysql I started the mysql daemon.. The I tried to log
in to my mysql database and got the message could not find mysql.sock
in /tmp.
In the mysql-configuration...
|
by: Oliver Etzel - GoodnGo.COM |
last post by:
Hello all,
after Installing mysql I started the mysql daemon.. The I tried to log
in to my mysql database and got the message could not find mysql.sock
in /tmp.
In the mysql-configuration...
|
by: Oliver Etzel - GoodnGo.COM |
last post by:
Hello all,
after Installing mysql I started the mysql daemon..
Then I tried to log in to my mysql database and got the message
could not find mysql.sock in /tmp.
In the mysql-configuration...
|
by: JW |
last post by:
Hi all,
I was fine running mysql, and for some reason, after the most recent
reboot of my machine, I get the following error and I try the following
subsequent commands to try to figure things...
| |
by: DevBoy |
last post by:
I installed the base MySQL 4.0 with Suse Linux and I try and start it and I
get anb issue with the fact that mysql.sock file does not exist in
/etc..../mysql/mysql.sock
I created a file and made...
|
by: OZ |
last post by:
the serproxy claim itself a multi-thread proxy thing.
I have sent email to write the original writer and there is no replay after
3 weeks. my configuration and setting are good.
...
|
by: vabh |
last post by:
Help from there, i want the IP Address of all computers which are connected in LAN with me. Its really urgent for me. I using one kind of coding which returns me IP Address of only one computer, but...
|
by: Roopesh |
last post by:
Hi,
I am using poplib's retr() to fetch mails from my gmail account. It
works fine, in some cases it gets stuck inside the retr() method and
does not come out.
From the logs I could find that...
|
by: jacob navia |
last post by:
Hi
We are rewriting the libc for the 64 bit version of lcc-win
and we have added a new field in the FILE structure:
char *FileName;
fopen() will save the file name and an accessor function
will...
|
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,...
| |
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
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...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |