Server Side:
-Delete the mswinsock control from the project
-Delete it from the control list too
-Add the sox.ocx
-Name it Socket
<!--[if !supportEmptyParas]--> <!--[endif]-->
frmServer.frm:
<!--[if !supportEmptyParas]--> <!--[endif]-->
delete or comment out the code you have for the old socket,
Socket_Accept
Socket_DataArrival
Socket_Close
<!--[if !supportEmptyParas]--> <!--[endif]-->
Now make a new Socket_State sub(go to the topleft combo box thing in the code window and select socket)
<!--[if !supportEmptyParas]--> <!--[endif]-->
The state sub is called everytime the state of the socket changes
0 = close
1 = listening ‘server thing
2 = Connecting ‘Client thing
3 = Accepted ‘Server thing, Sox automatically accepts connections
4 = Connected ‘Client thing
<!--[if !supportEmptyParas]-->
Code:
<!--[endif]-->
Private Sub Socket_State(ByVal Sox As Long, ByVal State As Long)
If Sox <> 0 Then 'not the main listening socket
Select Case State
Case 3
Call AcceptConnection(Sox)
Case 0
Call CloseSocket(Sox)
End Select
End If
End Sub
<!--[if !supportEmptyParas]-->
<!--[endif]-->
That should make sense now.
Now make a new DataArrival procedure.
<!--[if !supportEmptyParas]--> <!--[endif]-->
Private Sub Socket_DataArrival(ByVal Sox As Long, Data As Variant)
<!--[if !supportEmptyParas]--> <!--[endif]-->
End Sub
<!--[if !supportEmptyParas]--> <!--[endif]-->
Inside add
If IsConnected(Sox) Then
‘sox is the internal array index, no more control arrays, but you should know that if you read the readme :P.
Next add
<!--[if !supportEmptyParas]--> <!--[endif]-->
Call IncomingData(Sox, data)
End If
<!--[if !supportEmptyParas]--> <!--[endif]-->
You will change the incomingdata sub later
<!--[if !supportEmptyParas]--> <!--[endif]-->
It should end up looking like this..
Code:
Private Sub Socket_DataArrival(ByVal Sox As Long, Data As Variant)
If IsConnected(Sox) Then
Call IncomingData(Sox, Data)
End If
End Sub
<!--[if !supportEmptyParas]--> <!--[endif]-->
Private Sub Socket_Error(Sox As Long, Proc As String, Area As String, Code As Long, Abbr As String, Desc As String, DescEx As String)
'MsgBox "*** Error ***" & vbCrLf & vbTab & "Sox: " & Sox & vbCrLf & vbTab & "Proc: " & Proc & vbCrLf & vbTab & "Area: " & Area & vbCrLf & vbTab & "Code: " & Code & vbCrLf & vbTab & "Abbr: " & Abbr & vbCrLf & vbTab & "Desc: " & Desc & vbCrLf & vbTab & "DescEx: " & DescEx & vbCrLf & vbCrLf
End Sub
If you want you can add that, don’t need to, I commented it out on mine.
<!--[if !supportEmptyParas]--> <!--[endif]-->
Next: Incoming Data Sub
Change the header to look like this
Sub IncomingData(ByVal Index As Long, ByVal Data As Variant)
<!--[if !supportEmptyParas]--> <!--[endif]-->
Comment out or delete this:
'frmServer.Socket(Index).GetData Buffer, vbString, DataLength
<!--[if !supportEmptyParas]--> <!--[endif]-->
Add this, it converts the data to a string
Buffer = StrConv(Data, vbUnicode)
<!--[if !supportEmptyParas]--> <!--[endif]-->
Scroll down in that sub and fine this:
' Check if elapsed time has passed
Change the line below it to this:
Code:
Player(Index).DataBytes = Player(Index).DataBytes + UBound(Data)
<!--[endif]-->
Next go to the AcceptConnection sub
<!--[if !supportEmptyParas]-->
Code:
<!--[endif]-->
Sub AcceptConnection(ByVal Index As Long)
Dim i As Long
<!--[if !supportEmptyParas]--> <!--[endif]-->
If (Index = 0) Then
i = FindOpenPlayerSlot
If i <> 0 Then
' Whoho, we can connect them
Call SocketConnected(Index)
<!--[if !supportEmptyParas]--> <!--[endif]-->
Else
frmServer.Socket.Close (Index)
End If
End If
End Sub
Make it like that
<!--[if !supportEmptyParas]--> <!--[endif]-->
In Sub CloseSocket
Comment out where it closes the socket, kind of stupid making it close the socket since its getting called once the socket has closed.
<!--[if !supportEmptyParas]--> <!--[endif]-->
Change Function GetPlayerIP to
Code:
Function GetPlayerIP(ByVal Index As Long) As String
GetPlayerIP = frmServer.Socket.RemoteHostIP(Index)
End Function
Find ' Get the listening socket ready to go
Comment out both of the 2 lines under it which set the remotehost/port
<!--[if !supportEmptyParas]--> <!--[endif]-->
Comment/delete were it loads/unloads the sockets, you don’t need to do that anymore, its done internally.
<!--[if !supportEmptyParas]--> <!--[endif]-->
Find frmServer.Socket.Listen
-Change it to
frmServer.Socket.Listen frmServer.Socket.RemoteHostIP(0), Game_port (might need to change it to 127.0.0.1, I’m not sure)
<!--[if !supportEmptyParas]--> <!--[endif]-->Go to Sub ServerLogic
Get rid of that forloop which checks to see if it should close the socket
<!--[if !supportEmptyParas]--> <!--[endif]-->
Go to Sub UpdateCaption
Change it how you want, figure it out.
<!--[if !supportEmptyParas]--><!--[endif]--> Go to Function IsConnected
Add
Code:
If Index >= frmServer.Socket.Count Then
IsConnected = False
Exit Function
End If
This is to avoid an error if it checks a socket which isn’t there.
Code:
If frmServer.Socket.State(Index) = 3 Then
IsConnected = True
Else
IsConnected = False
End If
Now change the other if statement to this…
<!--[if !supportEmptyParas]--> <!--[endif]-->
Find .SendData (data here)
Change it to frmserver.socket.sendstring i/index(depending where it is), data
If you want to change this senddatatoall sub you can, you don’t have to though
Go to sub senddatatoall
Change it to
frmServer.Socket.broadcast data