none
Tcp error 10048: Only one usage of each socket address (protocol/network address/port) is normally permitted

    Question

  • I have developped an application that call a WCF service
    Two ChannelFactory<T> has been opened in try block and they are close in finally block.
    This operation is carried out in a while condition and it's executed 30000 times.

    while (i<30000)
    {
    try
    {
    OPen ChannelFactory<T>
    OPen ChannelFactory<T1>

    }
    finally
    {
    Close ChannelFactory<T>
    Close ChannelFactory<T1>

    }
    }

    When i arrive at 2000 calls i have this error :
    System.ServiceModel.CommunicationException: Could not connect to net.tcp://srv-mpl-int12:4151/ISupplier.
      Tcp error 10048: Only one usage of each socket address (protocol/network address/port) is normally permitted.
    ---> System.Net.Sockets.SocketException: Only one usage of each socket address (protocol/network address/port)
    is normally permitted


    if i add two keys in register keys in  : HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\TCPIP\Parameters
    MaxUserPort   = 32768
    and

    TcpTimedWaitDelay = 30
     
    i haven't this problem.

    I would like to know if it is the good manners to proceed for increase a TCP connections with WCF Services.

     

    Federico

     

     

    Thursday, October 19, 2006 1:06 PM

Answers

  • This is because you are running out of client side sockets. We will pool sockets, but we pool based on at the ChannelFactory level. If you close all your ChannelFactories then the pool will be released. Why are you creating and closing so many factories? I would recommend you don't churn through factories so quickly and rather create new client channels in your loop.

     

    Thursday, October 19, 2006 3:58 PM

All replies

  • This is because you are running out of client side sockets. We will pool sockets, but we pool based on at the ChannelFactory level. If you close all your ChannelFactories then the pool will be released. Why are you creating and closing so many factories? I would recommend you don't churn through factories so quickly and rather create new client channels in your loop.

     

    Thursday, October 19, 2006 3:58 PM
  • This code that i have published it's only a simulation of my real implementation.
    I opened a socket every time that i received a message because i work into a transactional context  for each message.
    My WCF service is in PerCall and  the end of transaction closes the ChannelFactory so i must create a new Channel Factory at every new transaction.
    The PerCAll choice for my WCF service is argued by LoadBalancing features needs.

    P.S. I received more than 15 messages per second

     

     

    Friday, October 20, 2006 3:10 PM
  • Dear Federico

     

    I have the same problem here. Could you please add more notes about how you solve the problem? I added the two keys in the registry with their parameters as suggested in the thread, but it didn't help me. I have 100 concurrent users in my load test and I am getting the following error immidatelly after the number of simultaneous users reached 100.

     

    Could not connect to net.tcp://localhost:8080/123/456/services/myservice. The connection attempt lasted for a time span of 00:00:00. TCP error code 10048: Only one usage of each socket address (protocol/network address/port) is normally permitted 127.0.0.1:8080.

     

    The WCF service is running as a windows service and I don't see any other instances running at the same time. I hope you will not suggest something like this.

     

    client.close();

     

    I tried many options to close the client, I used also try-finally block to dispose the client. It didn't help.

     

    Could you please tell me how to solve this?

     

    Thanks in advance

     

    Eskar,

    Tuesday, January 29, 2008 1:23 AM
  • Hi Federico,

     

    Can you please let me know what was the solution to your problem. I am also having a similar problem.

     

    Thanks in advance

    -Asfar

    Tuesday, March 04, 2008 3:50 PM
  • When you open a channel in a loop iterations the channel work in this manner : 
         - A socket is released before TcpTimedWaitDelay  milliseconds
        - A max number of socket that can be opened in same time is  MaxUserPort  
     
    This parameters are windows parameters.
     
    The good manner of use a ChannelFactory is  reuse a same channel.
     
    Open<IChanel> 
    for (int i = 0 ,i<10000;i++)
    {
        use cahnnel factory instance. and not open a new channel.

     

    Wednesday, March 05, 2008 5:38 PM
  • I don't know whether or not this is relevant but we got to this thread looking for the same error message. We created a proxy pool and noticed that when our service is hosted in Cassini that we get the same error message after calling a service method for about 3960 times or so but when we host the service in IIS it works like normal.

     

    This is the error message we received for a CalculatorService:

     

    Could not connect to http://localhost:3197/CalculatorService.svc. TCP error code 10048: Only one usage of each socket address (protocol/network address/port) is normally permitted 127.0.0.1:3197.

     

    Our pool was created based on this article:

     

    http://blogs.msdn.com/wenlong/archive/2007/11/14/a-sample-for-wcf-client-proxy-pooling.aspx

    Tuesday, March 18, 2008 12:04 PM
  • Hi Federico and Hi everybody else.

    I am facing exactly the same problem, same error and I guess same reason.

    This was how my code look like before reading this post:


     
    MailingWCFServiceClient client = new MailingWCFServiceClient();  
    for (int i = 0; i < 10000; i++)  
         client.QueueEmail(params);  
    client.Close();  





    instead this is how it looks like right now:

     
    MailingWCFServiceClient client = new MailingWCFServiceClient(); 
    IMailingWCFService channel = client.ChannelFactory.CreateChannel(); 
     
    for (int i = 0; i < 10000; i++) 
         channel.QueueEmail(params); 
     
    client.Close(); 


    ....but nothing has changed!!! Around the 1680th iteration, I still get the same error message:

    Tcp error 10048: Only one usage of each socket address (protocol/network address/port) is normally permitted


    Can anyone help me with this? Any advice will be more than welcome!!!

    Thanks in advance,
    Gian.
    • Proposed as answer by JonatCKNA Wednesday, March 18, 2009 5:07 PM
    Friday, November 21, 2008 4:22 PM
  • All,

        I am also encountering this error.  I have only one client open at a time.  I am having a client program connect to a server program running on the same PC.  When I close the client and rerun it, I get this exception.  But if I wait long enough before rerunning it, I don't get the exception.
        It sounds like the port becomes available after the garbage collector has freed up the resources used by the previous instance of the client.  But calling the garbage collector (GC.Collect(2)) doesn't seem to help.  Hopefully this will point someone in the right direction.

                                                                     Jon
    Wednesday, March 18, 2009 5:17 PM
  • Hi, I had also this problem but have found very simple solution that worsk...well at least in my app :-)




    MailingWCFServiceClient client = new  MailingWCFServiceClient();  
    for  ( int  i = 0; i < 10000; i++)  
         client.QueueEmail(params ); 
         Thread.Sleep(1000);          // just make a small pause :-)
    client.Close();
    Friday, April 03, 2009 8:10 AM
  • I found the above to work :)

    Top bloke!
    Tuesday, April 14, 2009 10:39 AM
  • Just wonder why you\anybody cannot send all parameters at once as array or at least in some parts. So you'll make less calls of service... Of cause it require to add some method on server side...

    Regards
    Tuesday, April 14, 2009 1:21 PM
  • In my case it's because the solution is a one-off that is not meant to be reproducible in the same manner in the future.

    I found the sleep method was adequate for me.
    Thursday, May 21, 2009 2:59 PM
  • Proxy connect error:Only one usage of each socket address(protocol/network address/port) is normally permitted.

     

    Change the net.outgoing_max_port & net.outgoing_port in utorrent advanced
    mode....set them to default. (0) is the default.

    Saturday, September 03, 2011 4:28 PM