• Welcome to Valhalla Legends Archive.
 

CHAT Server - stops listening [fixed]

Started by Eli_1, June 22, 2004, 09:31 PM

Previous topic - Next topic

Eli_1

Making a multi-room server that emulates the battle.net's CHAT protocol.

However, sometimes (seemingly randomly) clients will no longer be able to connect, and will be disconnected with with an error description of "forcefull rejected." ConnectionRequest isn't even being called, anyone know why this is happening?


ConnectionRequest:

Private Sub sckServer_ConnectionRequest(ByVal requestID As Long)
   'allow him to connect
   loadclient requestID
   
   
   
   
   
   'check to see if he's ipbanned
   
   
   'check to see if he has too many
   'bots loaded.
   
   
   
   Text1.Text = sckClients.UBound
End Sub





loadclient():

Public Sub loadclient(ByRef RID As Long)
   
   frmMain.sckServer.Close
   DoEvents
   frmMain.sckServer.Listen
   DoEvents
       
   Dim index As Integer
   Dim port As Long
   index = getopen
     
   If index = -1 Then
       Load frmMain.sckClients(frmMain.sckClients.UBound + 1)
       ReDim Preserve clients(UBound(clients) + 1)
       index = UBound(clients)
   End If
   
   
   With clients(index)
       .access = ACCESS_USER
       .constate = CONSTATE_WAITING
       .socketindex = index
   End With

   With frmMain.sckClients(index)
       .Close
       .LocalPort = PORT_START + index
       .Accept RID
       .SendData "Connection from [" & .RemoteHostIP & "]" & vbCrLf & vbCrLf & "0x03 (LOGINCHALLENGE)" & vbCrLf & "0x04 (NOECHO)" & vbCrLf & "0x0C (MAKEACCT)" & vbCrLf & vbCrLf
       DoEvents
   End With
   
End Sub


getopen (used so another instance of 'sckClients'
isn't created needlessly):

Private Function getopen() As Integer
   Dim i As Integer
   
   For i = 1 To UBound(clients)
       If frmMain.sckClients(i).State <> 7 Then getopen = i: Exit Function
   Next i
   
   getopen = -1
End Function

Banana fanna fo fanna



Fr0z3N

I'm to tired to read the code right now but its possible that somewhere the listening socket is being closed and left closed instead of reopened. That's happened to me a couple times, good luck.

Eli_1

This was just another stupid mistake by me...  ::)
Apparently you don't need to close the socket that's listening at all.