Sukasa
Posts: 787/2068 |
Eh, I later found the problem. I fixed it, it was client-side. Now, however, there is a new problem. If I have more than one client, then only the last person to join in will recieve messages, the rest can only send, and won't even recieve the messages they sent! |
Sukasa
Posts: 785/2068 |
um... yeah... I'm trying to get a program that acts as a server on a network, using the TCP protocol in VB6. My problem is, the server usually doesn't recieve connection requests after the first one. The way the server program was designed was that there would be 33 MS Winsock controls on the form, which is height 0 and width 0. There would be 32 or them in an array which handle connections, and one which sets them up, taking in connection requests and making an open port accept them. However, after the first connection, the "TCPConnector" winsock control stops recieving requests. Could someone please tell me what I am doing wrong with this code? There is also a timer, but that's used for mostly the caption at the bottom.
Dim openport(31) As Boolean
Dim Marqueescroll As Integer
Dim Marquee As String
Private Sub Form_Load()
Marqueescroll = 0
Me.Height = 0
Me.Width = 0
For a = 0 To 31
openport(a) = True
Next a
TCPConnector.Bind 2000, TCPConnector.LocalIP
TCPConnector.Listen
End Sub
Private Sub TCPClientport_Close(Index As Integer)
openport(Index) = True
Debug.Print "Connection lost"
End Sub
Private Sub TCPClientport_Connect(Index As Integer)
openport(Index) = False
Debug.Print "connection established"
End Sub
Private Sub TCPClientport_ConnectionRequest(Index As Integer, ByVal requestID As Long)
openport(Index) = False
Debug.Print "connection established"
End Sub
Private Sub TCPClientport_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Dim inarray() As Byte
Dim sendstring As String
TCPClientport(Index).GetData a, vbArray + vbByte, btyestotal
Select Case inarray(0)
Case 3
sendstring = ""
For a = 2 To UBound(inarray)
sendstring = sendstring + Chr$(inarray(a))
Next a
TCPClientport(inarray(1)).SendData Chr$(4) + sendstring
Case Else
sendstring = ""
For a = 0 To UBound(inarray)
sendstring = sendstring + Chr$(inarray(a))
Next a
Call SendToAll(sendstring, Index)
End Select
End Sub
Private Sub TCPConnector_ConnectionRequest(ByVal requestID As Long)
Debug.Print "Connection Request"
If PortAvailable Then
Debug.Print "Port available"
Debug.Print TCPClientport(AvailablePort).State
TCPClientport(AvailablePort).Accept requestID
Debug.Print TCPClientport(AvailablePort).State
openport(AvailablePort) = False
Else
Debug.Print "Port unavailable"
TCPConnector.Accept requestID
TCPConnector.SendData Chr$(&HFF)
a = 0
Do While a = 0
TCPConnect.PeekData a, vbByte, 1
Loop
End If
TCPConnector.Close
TCPConnector.Bind 2000, TCPConnector.LocalIP
TCPConnector.Listen
Debug.Print TCPConnector.State
End Sub
Private Function AvailablePort() As Integer
For a = 0 To 31
If openport(a) = True Then AvailablePort = a: Exit Function
Next a
AvailablePort = 0
End Function
Private Function PortAvailable() As Boolean
For a = 0 To 31
If openport(a) = True Then PortAvailable = True: Exit Function
Next a
PortAvailable = False
End Function
Private Function NumClients()
NumClients = 0
For a = 0 To 31
If openport(a) = False Then NumClients = NumClients + 1
Next a
End Function
Private Sub SendToAll(ToSend As String, skip As Integer)
For a = 0 To 31
If TCPClientport(a).State = sckConnected And a <> skip Then TCPClientport(a).SendData ToSend
Next a
End Sub
Private Sub Timer1_Timer()
Dim Marqueelength As Long
Marquee = ""
For a = 0 To 1
Marquee = Marquee + "GW Server -" + Str(NumClients) + " Clients" + " " + "Server IP: " + TCPConnector.LocalIP + " "
Next a
Marqueescroll = Marqueescroll + 1
Marqueelength = Len(Marquee) / 2
If Marqueescroll = Marqueelength Then Marqueescroll = 1
Me.Caption = Mid(Marquee, Marqueescroll, 22)
If TCPConnector.State <> sckClosed And TCPConnector.State <> sckConnected Then
TCPConnector.Close
TCPConnector.Bind 2000, TCPConnector.LocalIP
TCPConnector.Listen
End If
Debug.Print TCPConnector.State
End Sub
If anyone would like the whole .vbp project and form and everything, I can package the three things into a .zip file and upload for them.
EDIT: nvm. The error was "Address In Use", from the program connecting to the server code above. ...That's on the client side, right? |