No connection cold be made.. Final resolution needed.

Now after all the technical issues are resolved, the socket is created, the parameters are set I am facing a fundamantal issue. I kind of suspected from the outset that this could be the case and now I actually hit the wall.

I have a subscription to a stock information service which gives me an up to minute update of the market. I invoke this application which is a set of GUIs and try to tap into the actual PORT to divert the datagram tream to my database to process it my way.

When the application is connected to the server (money.net in this case) and using, let say, port 2453 I CANNOT open a socket at this endpoint. I get an error message:

No connection could be made because the target machine actively refused it

My hope was that setting an option

sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);

would help. It did not.

How can it be done if at all

I would appreciate your comments. I am sure there is someone out there who knows the answer or perhaps an answer.

Thanks in advance.



Answer this question

No connection cold be made.. Final resolution needed.

  • mojo99

    If I understand correctly you have an application that connects to a webservice and you want to be able to intercept the traffic between the application and the webservice   If this is the case, then the ReuseAddress option will not help you.  That option is so that you can Bind to the same source address that the application that is talking to the webservice has already bound to.  The solution of binding to the same port is not recommended as there is no gaunratee your application will receive all the data from the server.  

    NOTE: The behavior of the address reuse socket option will change with Longhorn for security reasons, please see the post about socket binding at http://blogs.msdn.com/wndp.

    I suggest either creating your own client to connect to the webservice or look at creating a network filter of some sort.  If you go the network filter route, you have two options (both require native and not managed code): LSPs or Windows Filtering Platform.  There are many docs on MSDN about creating LSPs and Windows Filtering Platform is new to Windows Vista. 



  • David_hary

    Please see
    http://blogs.msdn.com/wndp/archive/2005/08/03/Anthony_Jones.aspx
    That should answer all your questions

  • Tony Wu

    Hi mike,
    [On a related topic]I have a client-server application. When I try to connect to the server application using the loopback address, it runs fine, but if I give the actual IP or if I try to connect a server that run on another machine, it throws,
    "System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it"

    excpetion. Has it got something to do with .net security settings that we have in Adminstrative tools in the
    control panel I've just set the local intranet security to "full trust".
    Also I guess it's not something related to the
    firewall, Because I just tested it with my C++ C/S application with the same port. It works fine.
    Any help



  • Beltira

    I think you are getting confused about the BLOCKING property of sockets
    and blocking ports.
    1) PORTS
       YOu need a server that binds to a port and listens *before* clients can connect to it. So you should write a server first. 
       If you have a firewall you should enable that port so it won't get blocked

    2) Socket Blocking
    The socket blocking as *NOTHING* to do with firewall blocking
    Socket blocking = true means the call won't return until completes
    False means it returns immediately - after it initiates the operation. IN other words it is asynchrobous.

    Don't play with socket blocking - it is generally not needed.
    Just make sure that there is a server that is listening in a port and then connect to it. YOur error means that there is no server listening on that port. Make sure that the IP Address you are binding to on the server side is compatible.
    Don't bind to 127.0.0.1 and expect a differnt machine to reach that port.

    If you still have issues,
    please post your complete server and client samples


  • ghoffer

    Continuing my investigation I found this statement at an MSDN website:

    Bind throws an exception if the specific address and port combination is already in use.

    Can I use a DIFFERENT local address and the same port to read the data stream

    Thanks.

  • SuriP

    One more question please.

    If a client application listening at the socket has used setsockopt function and set up the SOL_SOCKET level option  
       SO_EXCLUSIVEADDRUSE to true
    do you think I will be able to override that

    Thanks.



  • Johan L

    Thank you for your comprehensive help. It will take me a few hours to digest everything you've said however I am making a steady progress. As a parallel project I set up a code project in Sockets in C++.

    Thanks.

  • root

    I keep working on the connection issue. I have broken the task into smaller parcels and now am trying to create an EndPoint, connect to a TCP port and check its options and possibly set the options too. I keep getting this error message. The firewall is disabled (program control in ZoneAlarm). It seems I have been able to connect to ports before and now it is not working. This port is not active, however.

      ee {"No connection could be made because the target machine actively refused it"} System.Exception {System.Net.Sockets.SocketException}

    When I check the "blocking" property of the socket (before it is connected) I can see that it is set to true.

    When I try to connect to an active port (ZoneAlarm connection) and change (edit) the property blocking = false manually in debugger right before the connection is made I get a different error message:

    "A non-blocking socket operation could not be completed immediately."

    My attempt to set the socket property UnblockSource to true with a statement like:

    sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.UnblockSource, true);

    also resulted in error. The error message was

    +  base {"An unknown, invalid, or unsupported option or level was specified in a getsockopt or setsockopt call"} System.ComponentModel.Win32Exception {System.Net.Sockets.SocketException}

    It appears that the option UnblockSource is unsuported because the statement

    UnblockSource unblockSource = new UnblockSource(true);

    resulted in errors.

    Appreciate any help.

    Thanks.






     



  • Muthu Arunachalam

    THANKS. Much appreciated. You've saved me a lot of time.

  • Andy_T

    Thanks, it is a very clearly wrtten paper and it answers most of my questions but not all.

    Still I do not understand why the socket I declare is created with the blocking attribute set to true, why if I change it to false during the edit, I get another error message (see my other post), why some of the optionName.value(s) of the socket that I try to set up programmatically are not recognized by the CLR (see my other post again).

    I wish I could get answers to those questions but in the meantime I will read the paper and some other stuff on the matter.

    Thanks again.

  • No connection cold be made.. Final resolution needed.