none
multiple clients connect same my server RRS feed

  • Question

  • ok this is how my listener works :

      public void Start()
            {
                Listener = new TcpListener(IPAddress.Any, 502);
                Listener.Start();
                while (true)
                {
                    TcpClient client = Listener.AcceptTcpClient();
                    Thread temp = new Thread( new ParameterizedThreadStart( TCPL));
                    temp.Start(client);
                }
                
            }
    
    
     private void TCPL ( object client)
            {
                TcpClient mClient = (TcpClient)client;
                while (true)
                {
                    NetworkStream stream = mClient.GetStream();
                    BinaryReader _reader = new BinaryReader(stream);
                    int temp1 = mClient.Available;
                    if (temp1 > 0 )
                    {
                            Byte[] message = new byte[temp1];
                        stream.Read(message, 0, message.Length);
                        String temp = Encoding.ASCII.GetString(message);
                        process(temp, stream);
                        }
                        
                    }
                }
    
    

    so that should work right ?

    to have like 3000 clients all connect to one server ?  I make a new thread for each connection

    Wednesday, December 2, 2015 1:50 PM

Answers

  • Web services and WCF are not the same thing. WCF is a .NET implementation of IPC that supports the same SOAP protocol that web services use but it can do so much more. While people tend to say they are writing a web service they generally mean they are writing a WCF service that uses the SOAP protocol.  Web services were obsoleted in .NET when WCF was released. You will only use WCF if you want to use the web service protocol.  On the client side communication can still occur using the web service protocol provided the WCF service was configured to allow WS protocols.

    Web API is a completely different beast and is completely based upon the same HTTP protocol that web browsers use. It serves a similar purpose but it is better suited for stateless calls (which is a good thing).

    Trying to describe web service, WCF and web API is beyond the scope of the forums. There are thousands of sites that describe all these technologies including MSDN. You really need to read up on them and decide which approach you want to go with. The fact that you're using an iPhone doesn't matter except for the fact that you won't want to use any WCF protocols that work with .NET only (or easily).

    For web API questions please post in the ASP.NET forums (http://forums.asp.net ).

    Saturday, December 5, 2015 5:10 PM
    Moderator

All replies

  • No that won't work.  Windows will not allow you to create that many threads (at least on x86). It is inefficient.  Additionally client machines don't allow that many simultaneous connections anyway.  You used to be limited to 100 outside of server OSes. You cannot write a couple lines of code and get that many connections working. You need to really invest in an existing client-server library rather than writing your own. If you really feel like writing your own then you have a long road ahead. At a minimum you'll need to do the following:

    • Create a thread pool (or use the existing one) to process requests as they come in
    • Use async listen to receive notifications when a client connects
    • Use async receives to receive requests from clients, process the request on a thread pool thread and then return the thread to the pool
    • Handle errors that will occur when processing requests because you don't want a thread pool to crash
    • Handle graceful shutdowns of all threads

    The key is that you cannot give each connection its own thread. You'll have to use thread pooling to share threads across all connections. You'll have to implement all the infrastructure to track this and it isn't trivial. Again an existing client-server library is a better option than trying to write this yourself. It requires advanced understanding of TCP and client-server architectures.

    Michael Taylor
    http://blogs.msmvps.com/p3net

    Wednesday, December 2, 2015 2:44 PM
    Moderator
  • Concurrent connections to the Windows O/S sever version is based on licenses agreement that you must buy for concurrent connection. 3,000 connections? Well, that is never going to happen.

    Secondly, maybe you should look into using a WCF TCP/IP service what you can configure the throttling to prevent DoS attacks, how many concurrent connections it will service at onetime and it spawns the threads as needed. 

    Wednesday, December 2, 2015 2:56 PM
  • I am making an app for the iphone and the app is going to pull from a database on a server and I am writing a server.

    is there a library, I can buy that will do this part for me ?

    also, how many connections can pull from a  database ?

    Wednesday, December 2, 2015 3:31 PM
  • We cannot answer these questions as there are too many variables.  iPhone means wireless so your network infrastructure will determine how many connections you can have.  Database wise it depends on the DB and the server it is running on.  Hosted or clouded databases tend to be limited by the service contract.  SQL itself can handle 1000s provided you're running a server OS but not necessarily concurrently.  Out of the box a single .NET app limits itself to 100 connections but that can be changed. The only way to know the limits is to test it after you've written your app.

    You will need to google for the available libraries to see which one's meet your needs.  Since you're targeting a non-.NET platform you'll have to get one that works well for that scenario.

    Wednesday, December 2, 2015 3:41 PM
    Moderator
  • I am making an app for the iphone and the app is going to pull from a database on a server and I am writing a server.

    is there a library, I can buy that will do this part for me ?

    also, how many connections can pull from a  database ?


    Personally, I think you are using the wrong technology. You should be using Webapi over http and let the Iphone connect that way using a browser based solution the browser on the Iphone.
    Wednesday, December 2, 2015 4:09 PM
  • hi is there a class you know about I can buy ?

    are somewhere I can learn more about this ?

    Wednesday, December 2, 2015 5:43 PM
  • so I  should use Asp.net web API?  How does that  work with better ?
    Thursday, December 3, 2015 1:39 PM
  • Web API is not necessarily the correct solution, it is just an existing solution. If you need for the iPhone app to be able to retrieve information from a server then web API, WCF or any # of other IPC mechanisms will work. You don't need to write a client-server system yourself. 

    If communication has to go both ways such that the server needs to call back to the client then web API isn't going to work. You'd need to use WCF or something.

    Please post questions related to ASP.NET and Web API in the ASP.NET forums (http://forums.asp.net ). 

    Thursday, December 3, 2015 2:51 PM
    Moderator
  • so I  should use Asp.net web API?  How does that  work with better ?

    It's the easiest to pickup and run with,  and it uses JSON, which is becoming the standard in data transmission over the Internet between devices and platforms.

    https://en.wikipedia.org/wiki/JSON

    http://www.raywenderlich.com/5492/working-with-json-in-ios-5

    Thursday, December 3, 2015 11:33 PM
  • Are WCF and  Web Service the same thing ? Are does WCF just use WebService.asmx ?

    Also will WCF Or WebService handle all the different connections from the different phones?

     

    Saturday, December 5, 2015 4:00 AM
  • Web services and WCF are not the same thing. WCF is a .NET implementation of IPC that supports the same SOAP protocol that web services use but it can do so much more. While people tend to say they are writing a web service they generally mean they are writing a WCF service that uses the SOAP protocol.  Web services were obsoleted in .NET when WCF was released. You will only use WCF if you want to use the web service protocol.  On the client side communication can still occur using the web service protocol provided the WCF service was configured to allow WS protocols.

    Web API is a completely different beast and is completely based upon the same HTTP protocol that web browsers use. It serves a similar purpose but it is better suited for stateless calls (which is a good thing).

    Trying to describe web service, WCF and web API is beyond the scope of the forums. There are thousands of sites that describe all these technologies including MSDN. You really need to read up on them and decide which approach you want to go with. The fact that you're using an iPhone doesn't matter except for the fact that you won't want to use any WCF protocols that work with .NET only (or easily).

    For web API questions please post in the ASP.NET forums (http://forums.asp.net ).

    Saturday, December 5, 2015 5:10 PM
    Moderator