|
-
Aug 14th, 2000, 08:58 PM
#1
Thread Starter
Junior Member
Hi,
I'm building a poker game, No Limit Texas Hold'em, using one server to host the game, deal the cards, calculate winners, etc., and I'm using several clients to connect to the server. The problem I am having is that usually after 2 or 3 (it varies for some reason) connections are made to the server by the clients, the server stops accepting connections. Does anyone know why this could be happening?
Here is how the server works: There is one winsock control, wsListen, that continuously listens for connect requests. When wsListen gets a connection request, it loads a new wsReceive array to handle the connection, and wsListen starts listening again.
Here's the code that is used:
Private Sub cmdStartServer_Click()
'Listens on a port
wsListen.LocalPort = 6500 'set the port
wsListen.Listen 'tell it to listen
cmdStartServer.Enabled = False
cmdStopServer.Enabled = True
lstStatus.Clear
lstStatus.AddItem "Listening on port 6500"
If wsListen.State = sckListening Then
sbMain.Panels(2).Text = "Status: Online"
sbMain.Panels(2).Picture = imgStatus.ListImages(1).Picture
End If
End Sub
Private Sub wsListen_ConnectionRequest(ByVal requestID As Long)
'this is the big cheese! When someone tries to login, it will open a diffrent
'winsock and accept the connection! That way wsListen keeps watching port 21
i = wsReceive.UBound + 1 'adds one to make sure we dont get errors
Load wsReceive(i) 'load a new winsock control
wsReceive(i).Close 'close it cuz of errors
wsReceive(i).Accept requestID 'accept the connection
lstStatus.AddItem "wsListen " & i & " Accepting Connection request: " & requestID
'set up wsListen for listening again
wsListen.Close
wsListen.LocalPort = 6500
wsListen.Listen
End Sub
Private Sub wsReceive_DataArrival(Index As Integer, ByVal bytesTotal As Long)
'data arrival, you can change this to do what you want.
Dim Data As String
Dim Command As String
wsReceive(Index).GetData Data 'gets the data
DoEvents
Command = Parse(Data, 1)
Select Case Command
Case "INF"
Set itmX = lvClient.ListItems.Add(, "c40" & Parse(Data, 2) & "i" & Index, Parse(Data, 3))
itmX.SubItems(1) = Parse(Data, 2)
itmX.SubItems(2) = "4022"
wsReceive(Index).Tag = "c40" & Parse(Data, 2) & "i" & Index
If lvClient.ListItems.Count = 0 Then
sbMain.Panels(1).Text = "0 Users Online"
End If
If lvClient.ListItems.Count = 1 Then
sbMain.Panels(1).Text = "1 User Online"
End If
If lvClient.ListItems.Count > 1 Then
sbMain.Panels(1).Text = lvClient.ListItems.Count & " Users Online"
End If
i = wsSend.UBound + 1 'adds one to make sure we dont get errors
Load wsSend(i) 'load a new winsock control
wsSend(i).Close 'close it cuz of errors
wsSend(i).RemoteHost = Parse(Data, 2)
wsSend(i).RemotePort = "4022"
wsSend(i).Connect 'connect to the client
End Select
End Sub
Thanks for any help!!!!!!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|