This is actually quite an interesting project you guys created, it almost solves two problems, one for my AppGameKit problem and one problem I wanted to fix for months now.
Though I am still trying to figure out why AppGameKit doesn't send message data.
It keeps crashing when I send a message, or the server just doesn't get the data.
I am using vb6 to learn a bit about how AppGameKit communicates (to little success)
My vb6 application:
Option Explicit
Private intWinsockCnt As Integer
Private Sub ClearInfoList()
Dim i_Cnt As Integer
For i_Cnt = 1 To 10000
SafeCloseSocket WSocket(i_Cnt)
Next i_Cnt
intWinsockCnt = 0
End Sub
Private Sub SafeCloseSocket(Wsock As Winsock)
On Error GoTo SafeCloseSocket_Err
Wsock.Close
Unload Wsock
Exit Sub
SafeCloseSocket_Err:
End Sub
Private Sub btn_Action_Click()
If Me.btn_Action.Caption = "Listen" Then
WSocket(0).Close
WSocket(0).LocalPort = txt_Port.Text
WSocket(0).Listen
Log "-------------------------Server Started-------------------------"
Me.btn_Action.Caption = "Stop"
Else
WSocket(0).Close
Log "-------------------------Server Stopped-------------------------"
Me.btn_Action.Caption = "Listen"
ClearInfoList
End If
End Sub
Private Sub Log(s_Line As String)
Dim l_Cnt As Long
Dim l_File As Long
Dim s_Filename As String
Me.ls_Log.AddItem s_Line
If Not ls_Log.ListCount = 0 Then
If c_File.OpenFile(App.Path & "\System_Log.log", l_File, True, AppendF, ReadWriteF, LockReadWriteF) Then
'For l_Cnt = 0 To ls_Log.ListCount - 1
Print #l_File, Clip(s_Line)
DoEvents
'Next l_Cnt
Close #l_File
End If
End If
End Sub
Private Sub btn_Ping_Click()
Dim i_Cnt As Integer
For i_Cnt = 1 To intWinsockCnt
If WSocket(intWinsockCnt).State = sckConnected Then
WSocket(intWinsockCnt).SendData Chr(9) & " ping"
End If
Next i_Cnt
End Sub
Private Sub WSocket_Close(Index As Integer)
Log "< Connection Closed From:" & WSocket(Index).RemoteHostIP
Unload WSocket(Index)
End Sub
Private Sub WSocket_ConnectionRequest(Index As Integer, ByVal requestID As Long)
Dim t_RemoteInfo As RemoteMachineInfoType
If intWinsockCnt = 0 Then
intWinsockCnt = 1
End If
intWinsockCnt = intWinsockCnt + 1
Load WSocket(intWinsockCnt)
WSocket(intWinsockCnt).Accept requestID
Log "< Connection Request From:" & WSocket(intWinsockCnt).RemoteHostIP
Wait (20)
WSocket(intWinsockCnt).SendData "Connected"
End Sub
Private Sub WSocket_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Dim strData As String
Dim intCnt As Integer
Dim btyData() As Byte
Dim i_btyDataCount As Integer
WSocket(Index).GetData btyData, vbByte
'WSocket(Index).GetData strData, vbString
'Debug.Print "Data" + strData
strData = ""
For i_btyDataCount = 0 To UBound(btyData)
Select Case btyData(i_btyDataCount)
Case 0:
Case 9: strData = strData + "|"
Case Else: strData = strData + Chr(btyData(i_btyDataCount))
End Select
' If Not btyData(i_btyDataCount) = 0 Then
' strData = strData + Chr(btyData(i_btyDataCount))
' End If
Next i_btyDataCount
Log "> Got Data From:" & WSocket(Index).RemoteHostIP & "=" & Clip(strData)
'strData = Replace(strData, vbCrLf, "")
'Debug.Print "Data" + strData
'MsgBox strData
' If Clip(strData) = "AMICONNECTED" Then
' WSocket(Index).SendData "AMICONNECTED-YES"
' Else
' Log "> Got Data From:" & WSocket(Index).RemoteHostIP & "|" & Clip(strData)
' 'Me.ls_Log.AddItem "> Data:" & strData
' WSocket(Index).SendData "CONTINUE"
' End If
End Sub
My AppGameKit App:
#include "functions.agc"
// Project: NetworkTest
// Created: 2015-09-16
// set window properties
SetWindowTitle( "NetworkTest" )
SetWindowSize( 1024, 768, 0 )
// set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
Global g_strPrintMessage as string[100]
Global g_intPrintMessageCount as integer = 0
Global g_intNetworkID as integer = 0
Global g_intConnected as integer = 0
Global g_intMessageID as integer = 0
Global g_strMessage as string = ""
//"127.0.0.1",4503, "MainClient"
g_intNetworkID = JoinNetwork("127.0.0.1", 4503, "AGKclient")
//g_intNetworkID = JoinNetwork("192.168.30.178", 4503, "AGKclient")
time# = timer() + 3
while time# > timer()
Print("New ID")
Print(g_intNetworkID)
sync()
endwhile
do
Print(ScreenFPS())
Print(GetDeviceName() + " " + GetDeviceType() + " [" + GetDeviceBaseName() + "]")
Print(GetDeviceIP())
Print(GetDeviceID())
Print("NetworkID : " + str(g_intNetworkID))
Print("Number Of Clients : " + str(GetNetworkNumClients(g_intNetworkID)))
g_intMessageID = GetNetworkMessage(g_intNetworkID)
if not g_intMessageID = 0
g_strMessage = Trim(GetNetworkMessageString(g_intMessageID))
g_intPrintMessageCount = g_intPrintMessageCount + 1
g_strPrintMessage[g_intPrintMessageCount] = g_strMessage + " Recieved"
endif
Print("Message ID : " + str(g_intMessageID))
Print("")
for i_Count = 65 to 90
if GetRawKeyPressed(i_Count) = 1
g_intPrintMessageCount = g_intPrintMessageCount + 1
g_strPrintMessage[g_intPrintMessageCount] = GetRawKeyName(i_Count) + " Pressed"
if g_intNetworkID > 0
g_intPrintMessageCount = g_intPrintMessageCount + 1
g_strPrintMessage[g_intPrintMessageCount] = "Sending Message"
msg = CreateNetworkMessage()
//AddNetworkMessageInteger(msg,10)
//AddNetworkMessageInteger(msg,cMT2_GENERIC)
AddNetworkMessageString(msg,"test")
SendNetworkMessage(g_intNetworkID,0,msg)
DeleteNetworkMessage(msg)
g_intPrintMessageCount = g_intPrintMessageCount + 1
g_strPrintMessage[g_intPrintMessageCount] = "Message Sent"
else
g_intPrintMessageCount = g_intPrintMessageCount + 1
g_strPrintMessage[g_intPrintMessageCount] = "Cannot Send Message"
endif
endif
next i_Count
for i_Count = 1 to g_intPrintMessageCount
Print(g_strPrintMessage[i_Count])
next i_Count
if GetRawKeyPressed(27) = 1
Exit
endif
Sync()
loop
CloseNetwork(g_intNetworkID)
function GetRawKeyName(i_Key as integer)
s_Return as string
s_Return = ""
select i_Key
case 27:
s_Return = "Escape"
endcase
case 65
s_Return = "KEY_A"
endcase
case 66:
s_Return = "KEY_B"
endcase
case 67:
s_Return = "KEY_C"
endcase
case 68:
s_Return = "KEY_D"
endcase
case 69:
s_Return = "KEY_E"
endcase
case 70:
s_Return = "KEY_F"
endcase
case 71:
s_Return = "KEY_G"
endcase
case 72:
s_Return = "KEY_H"
endcase
case 73:
s_Return = "KEY_I"
endcase
case 74:
s_Return = "KEY_J"
endcase
case 75:
s_Return = "KEY_K"
endcase
case 76:
s_Return = "KEY_L"
endcase
case 77:
s_Return = "KEY_M"
endcase
case 78:
s_Return = "KEY_N"
endcase
case 79:
s_Return = "KEY_O"
endcase
case 80:
s_Return = "KEY_P"
endcase
case 81:
s_Return = "KEY_Q"
endcase
case 82:
s_Return = "KEY_R"
endcase
case 83:
s_Return = "KEY_S"
endcase
case 84:
s_Return = "KEY_T"
endcase
case 85:
s_Return = "KEY_U"
endcase
case 86:
s_Return = "KEY_V"
endcase
case 87:
s_Return = "KEY_W"
endcase
case 88:
s_Return = "KEY_X"
endcase
case 89:
s_Return = "KEY_Y"
endcase
case 90:
s_Return = "KEY_Z"
endcase
endselect
endfunction s_Return
And the vb6 application log file:
Quote: "
-------------------------Server Started-------------------------
< Connection Request From:127.0.0.1
> Got Data From:127.0.0.1=|AGKclient
> Got Data From:127.0.0.1=
< Connection Closed From:127.0.0.1
< Connection Request From:127.0.0.1
> Got Data From:127.0.0.1=|AGKclient
-------------------------Server Stopped-------------------------
"