473,320 Members | 1,974 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,320 software developers and data experts.

How to close another socket

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.

Nov 17 '05 #1
4 1631
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,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Nuno Magalhaes" <nu************@hotmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
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.

Nov 17 '05 #2
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.

Ignacio Machin ( .NET/ C# MVP ) wrote:
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,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Nuno Magalhaes" <nu************@hotmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
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.


Nov 17 '05 #3
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,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Nuno Magalhaes" <nu************@hotmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
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.

Ignacio Machin ( .NET/ C# MVP ) wrote:
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,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Nuno Magalhaes" <nu************@hotmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
> 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.
>

Nov 17 '05 #4
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.

Ignacio Machin ( .NET/ C# MVP ) wrote:
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,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Nuno Magalhaes" <nu************@hotmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
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.

Ignacio Machin ( .NET/ C# MVP ) wrote:
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,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Nuno Magalhaes" <nu************@hotmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
> 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.
>


Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: drs | last post by:
Hi, I have a program which opens a socket server in a thread. I need for the server to listen on the socket for a certain amount of time (say, ten seconds or so) and then close it, and am...
3
by: Daniel | last post by:
TcpClient close() method socket leak when i use TcpClient to open a connection, send data and close the TcpClient with myTcpClientInstance.Close(); it takes 60 seconds for the actual socket on...
9
by: AA | last post by:
This is making me crazy!! Please, if some body can help me. I'm testing a ver simple socket client. In my test I just open and close a connection (in a loop) to my local IIS server (port 80)...
4
by: Chris Tanger | last post by:
Context: C# System.Net.Sockets Socket created with constructor prarmeters Internetwork, Stream and TCP everything else is left at the default parameters and options except linger may be changed...
3
by: Jimbo | last post by:
Hi Guys, I'm sorry if you have heard this one before but searching the net hasn't found a solution. I am using Socket in a client to connect to a server. However, after I've finished sending...
4
by: Haim | last post by:
it is very strange for me that a simple event of closing socket that was in the the winsock object of vb6 , i didn't found yet in the vb.net the only way i found is to try to send something to...
14
by: =?Utf-8?B?TWlrZVo=?= | last post by:
I have a sync socket application. The client is blocked with Socket.Receive(...) in a thread, another thread calls Socket.Close(). This unblock the blocked thread. But the socket server is still...
1
by: Sparky74 | last post by:
Hi Everybody. I have been searching for many hours for an answer to this problem. I hope somebody can help me. I have a C# .NET client application that connects to a TCP/IP C++ server application...
3
by: A. W. Dunstan | last post by:
I have an application that wants to open a Socket, write data and close the socket. A persistent connection would be nice, but it's intended to operate in an environment where the network...
0
by: meLlamanJefe | last post by:
I have the following code snippet that is used in a simple multi-threaded server program I am testing. The ServerSocket class binds to a port and creates a listening socket. Then it sits and waits...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.