DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 12 of 12

Thread: Multiple Winsock Clients

  1. #1
    Join Date
    Sep 2004
    Location
    Northampton,United Kingdom
    Posts
    230

    Multiple Winsock Clients

    Hi all,

    I am using the winSock system to allow me to share my Printer (serial) on my system via winsock. I can connect one module to the system with NO PROBLEM but when I try to connect another module to the server app I get the following

    SOCKET Error 10061: Connection is Forcefully rejected.

    How can I allow More then one client to access my Server app?

    Is it the server app I need to modify or the client app or both?

    Thanks

    Andy

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    You can only have one connection at a time on a given port. In order to support multiple simultaneous connections, you must change the server app to listen on multiple ports, and you must change the client app to use an available port.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Sep 2004
    Location
    Northampton,United Kingdom
    Posts
    230
    And How do I go about doing that?

  4. #4
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819
    one way is using an array of the socket object ...
    wisck(i).port = 8008
    wisck(i+1).port = wisck(i).port + 1
    in both sides as Phil said, in the server and the client app.

    another way is using a queue manager, which has the main role to handle requests in ONE ONLY port, and save them in a queue, later manage the queue with the server application, when it becomes free, send to it the next role and so on ...
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  5. #5
    Join Date
    Sep 2004
    Location
    Northampton,United Kingdom
    Posts
    230
    How would i use the queue manager? that sounds like what I want the system to do

    as it is a printer control module it would only have to do one job at a time

    any examples would be most welcomed

    Thanks

    Drew

  6. #6
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819
    ok again there is two options:
    the easiest is to make the client attempt to try to connect at a constant interval up to reach a valid connection ... this method won't be fear with a big number of users that's maybe someone will wait too much and another lucky one reach and open a connection faster than the older one ...

    the second solution is to make a queue manager at the server side, it will just write the received requests nothing more ... for example if there is 3 attempt to print in the same time, this program will store the IP's say respectively of the requests ... and it will wait until the printer is free and ready for new job, then the queue manager will send a small signal to the first client in the queue allowing it to communicate with the printer and send its job .. and so on ...
    maybe there is other ideas to implement this queue manager , but finally as you can see it will be server system and resources friendly, and for the client too ... I suppose the maximum number of sockets that you need to make this process with a very large number of users is 3 sockets only ! :
    -one to receive requests and store them only.
    -one to send signals to the client .
    and one for the direct communication with the client and the printer .
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  7. #7
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819
    You may get another problem if there is two or more requests to print something at closely the same time ... here attempting to reconnect with a very short interval or maybe infinite while loop won't be a big problem because the connection time is very short and will end very fast so we may not notice a big delay to accept the request here ...
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  8. #8
    Join Date
    Sep 2004
    Location
    Northampton,United Kingdom
    Posts
    230
    Well what I am trying to do is create a printer module that will allow my EPoS Appication and Card printer module and Cheque Print Module to use the same printer

    I am running all theses locally

    the PoS connect on port 50505
    The Cheque printer conects on 50506
    The Card moudle connects on 50507

    I need the systems to work with all 3 at any time BUT It should only print one at a time

  9. #9
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819
    3 only modules to connect to the printer ? so you don't need to deal with or worry about big number of users as i said before ...
    ok you have three ports for each module, and in the server you should have three sockets each of them is listening to a different port ... now when you receive a job, the queue manager role is not in the network interface but all what it has to do is to hold received requests until the printer is ready for a new job .. you may just implement this by using a listbox ... when you receive a job insert it in the listbox ... and a timer which will check if the printer is free , then it will send to it the first item in the listbox and remove it from the list at the same time ... if you receive another job it will be appended at the end of the listbox and so on ... hope this can help.
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  10. #10
    Join Date
    Sep 2004
    Location
    Northampton,United Kingdom
    Posts
    230
    So do I need to have 3 winstock controls on my form?? or can I set the one i have to allow 3 connections?

  11. #11
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Each control can only listen on a single port, so you would need three controls to allow three simultaneous connections.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  12. #12
    Join Date
    Mar 2008
    Posts
    5
    Code:
    wServer.Listen
    
    Sub wServer_ConnectionRequest(RequestID as Long) 
       wClient(GetAvailableClient).Accept(RequestID)
    End Sub
    This keeps the Server listening on the same port while spawning client nodes. in the GetAvailableClient() function you can do something like this:
    [keep in mind you must have a Winsock control (wClient with .Index of 0) on the form at design time]
    Code:
    Function GetAvailableClient() as Integer
      Static LoadedSockets(100) as boolean 
      Static NextSock as integer 
      If NextSock > 0 and LoadedSockets(NextSock) = False then
        Load wClient(NextSock)
        LoadedSockets(NextSock) = True
      End if
      NextSock = NextSock + 1
      GetAvailableSocket = NextSock - 1  'Because you return the one you just created
    End function
    You should definitely put a bounds check on there (if > 100...) and probably dress up the function to check for closed/disconnected/errored sockets, finish closing them and then return that id.

    Let me know how it goes
    Last edited by the_mrrobert; 03-06-2008 at 12:07 PM.

Similar Threads

  1. Replies: 1
    Last Post: 01-10-2007, 05:53 PM
  2. Many (Multiple) Winsock Control
    By Joey_G in forum VB Classic
    Replies: 1
    Last Post: 03-10-2005, 01:20 PM
  3. Winsock:1server Multiple Clients
    By FELIX in forum VB Classic
    Replies: 10
    Last Post: 04-24-2001, 08:03 AM
  4. Winsock:1server Multiple Clients
    By FELIX in forum VB Classic
    Replies: 0
    Last Post: 04-20-2001, 11:43 AM
  5. 1 server multiple clients
    By Peter Tribout in forum Enterprise
    Replies: 3
    Last Post: 09-19-2000, 11:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center