How to close another socket

N

Nuno Magalhaes

How can I close another socket belonging to the same application but
all know is the IP address of the client and the port number that the
server is listening on.

Sounds like a firewall I know but I would like to know how to do it in
C#. Can anyone help me?

Thanks,
Nuno Magalhaes.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

There is no way of doing that, you need to keep a reference to that
particular socket.

Even so unless you can assure that you will receive only one request from
that IP you are risking your self of closing another connections.
A TCP communication is uniquely identified by 4 values : source IP/port dest
IP/port unless you have those 4 values you can not uniquely identify it.


BTW, this is not how a firewall works, a firewall do not close a socket, it
simply intercept the package before it reach the app (in case of inbound
traffic ) if the package is not allow it just discard it.


cheers,
 
N

Nuno Magalhaes

There is a way but using the Packet Filtering API (PAPI) and C++. This
link shows it all: http://www.codeproject.com/tools/firewallpapi.asp.

I think packet filtering API comes with Microsoft Windows SDK, but I
had to move out on my programming language. It does not compensate and
I really don't need it so much after all since I can reprogram the
restrictions in my windows firewall.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Well, you would have to check the code and see how he does it, most probably
this will throw an exception in your code.

Why can't you just keep a reference to the socket in a variable?


cheers,
 
N

Nuno Magalhaes

Because I'm using Windows Media Encoder Package and SDK to broadcast
the streaming video from my webcamera. This is done automatically by
the interfaces of WMEncoder.Broadcast and the only thing I get is to
get registered on a event that is raised when a connection occurs and
all the info I get is the IP.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top