Convert TCPInformation to socket

A

alex

Hello,

My program is connected to a box. I connect to the box thanks to a
socket. My problem is:

I open an other module of my program. I can't have access to the
instance of my socket. So I would like to get the active TCP
connections and get the related socket.

I tried with the method GetActiveTCPConnections. I see my TCP
connections. How can I get the related socket?

I can only have one TCP connection on the box. So if I want to connect
one more time I have an exception. And If I disconnect my socket and
reconnect. I think it is not the best solution.

Do you have an idea?
 
P

Peter Duniho

alex said:
Hello,

My program is connected to a box. I connect to the box thanks to a
socket. My problem is:

I open an other module of my program. I can't have access to the
instance of my socket. So I would like to get the active TCP
connections and get the related socket.

I tried with the method GetActiveTCPConnections. I see my TCP
connections. How can I get the related socket?

I can only have one TCP connection on the box. So if I want to connect
one more time I have an exception. And If I disconnect my socket and
reconnect. I think it is not the best solution.

Do you have an idea?

Given the information returned by TcpConnectionInformation, the best you
could do is open a second socket, enabling the ReuseAddress option.
But, even that is a very bad choice unless you have coordination between
the code using the two different sockets.

Unfortunately, you're not specific about why you "can't have access to
the instance of your socket", but it really would be the best way if you
need to reuse the connection in a different module, to figure out a way
for the first module to hand over ownership of the socket to the second
module.

Otherwise, disconnect/reconnect is probably the best, safest, most
maintainable approach, however inefficient it might be.

Pete
 

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