Results 1 to 6 of 6

Thread: Winsock Server app

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Location
    Trondheim, Norway
    Posts
    65

    Question

    If I was to make a server application (LAN), and I want to use winsock, how do I accept more than one connection?

    Do I have to Load a new winsock component for each connection, like have one winsock to start with, then if one connects, another one is loaded etc.

    But won't this create a conflict if they all listen to the same port?

    Any solution is a good solution

    D

  2. #2
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177
    See Using the Winsock Control - paragraph "Accepting More than One Connection Request".

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Location
    Trondheim, Norway
    Posts
    65
    Thanks, I've done that now. It works...

    D

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Location
    Trondheim, Norway
    Posts
    65
    Now, a new problem.

    If someone disconnects, the wsock that that person used, is still there. That means that a new wsock is loaded for every new connection even though lots of wsocks are available.

    I tried this code, but I wasn't allowed to change the index...

    ---------
    Unload TcpServer(Index)

    For i = Index + 1 To intMax
    TcpServer(i).Index = TcpServer(i).Index - 1
    Next
    intMax = intMax - 1
    ---------

    D

  5. #5
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177
    Try looping through the control array looking for the first socket that has been closed and do another Accept.

    I haven't tried this but I think it should work. Let me know if it requires any other steps. I don't think it will because I have seen my socket state go from sckConnected to sckClosing to sckClosed when the other side shut down. So with a state of sckClosed, you should be able to do the Accept.


  6. #6
    Fanatic Member
    Join Date
    Jul 2000
    Location
    Manchester NH
    Posts
    833
    sock(0) is listening
    NumSocks is the total number of socks
    ----------------
    connection request



    for a = 1 to NumSocks
    if sock(a).state = 0 then 50
    next a

    NumSock=NumSocks+1

    load sock(NumSocks)
    a=NumSocks

    50

    Sock(a).accept requestid

    etc etc

    Kurt Simons
    [I know I'm a hack but my clients don't!]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width