|
-
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!!!!!!!
-
Aug 19th, 2000, 03:38 AM
#2
I dont know whats wrong, but you can take a look at Fox's winsock demo
http://foxmccloud.tsx.org
-
Aug 19th, 2000, 05:22 AM
#3
Guru
I optimized some parts. Didn't find a problem, but might have fixed it randomally in the optimizing.
If there are other problems, they might be in code that you didn't put here...
You'll get over it. 
Try this:
Code:
Private Sub cmdStartServer_Click()
'Listens on a port
wsListen.LocalPort = 6500 'set the port
Call wsListen.Listen 'tell it to listen
cmdStartServer.Enabled = False
cmdStopServer.Enabled = True
Call lstStatus.Clear
Call lstStatus.AddItem("Listening on port 6500")
sbMain.Panels(2).Text = "Status: Online"
sbMain.Panels(2).Picture = imgStatus.ListImages(1).Picture
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 6500
i = wsReceive.UBound + 1 'adds one to make sure we dont get errors
Call Load(wsReceive(i)) 'load a new winsock control
Call wsReceive(i).Accept(requestID) 'accept the connection
Call lstStatus.AddItem("wsListen " & i & " Accepting Connection request: " & requestID)
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
Call 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 = 1 Then
sbMain.Panels(1).Text = "1 User Online"
Else
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).RemoteHost = Parse(Data, 2)
wsSend(i).RemotePort = 4022
wsSend(i).Connect 'connect to the client
End Select
End Sub
-
Aug 20th, 2000, 01:11 PM
#4
Thread Starter
Junior Member
The Call statement won't do jack. Like I mentioned before, wsListen and wsReceive are Winsock controls. The code I posted is where the problem exists.
I'm pretty sure the problem is that all the clients connect to port 6500. I tried having all the clients connect to a different port (6500, 6501, 6502, and 6503) and it worked fine.
Thanks for the 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
|