Print Page | Close Window

SOX instead of Winsock

Printed From: Mirage Source
Category: Tutorials
Forum Name: Submitted Tutorials
Forum Discription: Tutorial submissions for MSE are posted here, waiting for approval
URL: http://ms.shannaracorp.com/backup-forums/forum_posts.asp?TID=87
Printed Date: 20 December 2006 at 6:03pm
Software Version: Web Wiz Forums 8.01 - http://www.webwizforums.com


Topic: SOX instead of Winsock
Posted By: grimsk8ter11
Subject: SOX instead of Winsock
Date Posted: 09 February 2006 at 7:27pm

Server Side:

-Delete the mswinsock control from the project

-Delete it from the control list too

-Add the sox.ocx

-Name it Socket

 

frmServer.frm:

 

delete or comment out the code you have for the old socket,

             Socket_Accept

             Socket_DataArrival

             Socket_Close

 

Now make a new Socket_State sub(go to the topleft combo box thing in the code window and select socket)

 

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

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

That should make sense now.

Now make a new DataArrival procedure.

 

Private Sub Socket_DataArrival(ByVal Sox As Long, Data As Variant)

 

End Sub

 

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

 

        Call IncomingData(Sox, data)

    End If

 

You will change the incomingdata sub later

 

It should end up looking like this..


Private Sub Socket_DataArrival(ByVal Sox As Long, Data As Variant)

    If IsConnected(Sox) Then

        Call IncomingData(Sox, Data)

    End If

End Sub

 

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.

 

Next: Incoming Data Sub

Change the header to look like this

Sub IncomingData(ByVal Index As Long, ByVal Data As Variant)

 

Comment out or delete this:

'frmServer.Socket(Index).GetData Buffer, vbString, DataLength

 

Add this, it converts the data to a string

 Buffer = StrConv(Data, vbUnicode)

 

Scroll down in that sub and fine this:

' Check if elapsed time has passed

Change the line below it to this:


Player(Index).DataBytes = Player(Index).DataBytes + UBound(Data)


Next go to the AcceptConnection sub


Sub AcceptConnection(ByVal Index As Long)

Dim i As Long

 

    If (Index = 0) Then

        i = FindOpenPlayerSlot

       

        If i <> 0 Then

             ' Whoho, we can connect them

             Call SocketConnected(Index)

 

        Else

             frmServer.Socket.Close (Index)

        End If

    End If

End Sub

Make it like that

 

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.

 

Change Function GetPlayerIP to


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

 

Comment/delete were it loads/unloads the sockets, you don’t need to do that anymore, its done internally.

 

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)

 Go to Sub ServerLogic

Get rid of that forloop which checks to see if it should close the socket

 

Go to Sub UpdateCaption

Change it how you want, figure it out.

Go to Function IsConnected

Add


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.


If frmServer.Socket.State(Index) = 3 Then

        IsConnected = True

    Else

        IsConnected = False

    End If

Now change the other if statement to this…

 

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




Replies:
Posted By: Sync
Date Posted: 26 February 2006 at 12:57pm
... Url to get Sox.ocx?



Print Page | Close Window

Bulletin Board Software by Web Wiz Forums version 8.01 - http://www.webwizforums.com
Copyright ©2001-2006 Web Wiz Guide - http://www.webwizguide.info