Winsock API troubles (data send but not recived)
Hy, im programing online game...
When client connect to server enything is great, client send data to server and server sends data back but when server sends user data to client, server sings that the data was sent without eny trubles but client doesnt recive enything ---> it even doesnt trigger socket_dataarrial on client and even then when i try to send data to server on server nothing happens...
Im using TCP protocol and im testing this on localloop back(127.0.0.1)
and in background is running loop(with doevents) for drawing onscreen and when i close on client server sings error --> Connection closed due to timeout or other faliture(errnum: 10053)
Can enyone give me idea what can be wrong?
can be the loop the trouble or is the problem that the data was recived but the event was not triggered?
Re: Winsock API troubles (data send but not recived)
Hello,
I didnt understand, you are using Winsock component or API for that?
And you should show some code, its hard to figure out the problem without seeing the code...
//jean
Re: Winsock API troubles (data send but not recived)
Sory for my bad english.
Here is code for my server:
VB Code:
Private Sub socket_DataArrival(index As Integer, ByVal bytesTotal As Long)
Dim buffer As String
Dim buffer2 As String
Dim sckDataType As Integer
Dim clientinfo As CLIENTINFO_TYPE
Dim serverINFO As SERVERINFO_TYPE
Dim ClientCMD As CMD_TYPE
With serverINFO
.clientID = index
.clientType = 2
.ConnAllowed = True
.serverIP = socket(0).LocalIP
End With
socket(index).GetData buffer2
''Debug.Print Len(buffer)
buffer = ICStr(buffer2, 0)
sckDataType = ICStr(buffer2, 1)
List1.AddItem sckDataType
List1.AddItem "Getting new info"
If sckDataType = 0 Then
Call CopyMemory(VarPtr(clientinfo), StrPtr(buffer), LenB(clientinfo))
If CleanString(clientinfo.ver) = "0001" Then
buffer = Space(Len(serverINFO))
Call CopyMemory(StrPtr(buffer), VarPtr(serverINFO), LenB(serverINFO))
socket(index).SendData OGStr(5, buffer)
End If
ElseIf sckDataType = 10 Then '' if check cmd
Call CopyMemory(VarPtr(ClientCMD), StrPtr(buffer), LenB(ClientCMD))
If ClientCMD.cmd = 1 And ClientCMD.cmdtype = 0 Then
Dim usersbuffer As USERME_TYPE: usersbuffer = users(0)
buffer = Space(Len(usersbuffer))
'''copy udt to string
Call CopyMemory(StrPtr(buffer), VarPtr(usersbuffer), LenB(usersbuffer))
List1.AddItem "Trying to send back user list"
''''this sends packet to client but client doesnt recive it
socket(index).SendData OGStr(1, buffer)
buffer = ""
End If
Else
End If
End Sub
hire is client code
VB Code:
Private Sub socket_DataArrival(ByVal bytesTotal As Long)
Dim SCKdatatype As Integer
Dim ClientCMD As CMD_TYPE
'On Error Resume Next
strICStr = ""
socket.GetData strICStr, vbString
If strICStr = "" Then
socket.PeekData strICStr, vbString
End If
SCKdatatype = ICStr(strICStr, 1) ''gettype
strICStr = ICStr(strICStr, 0) ''getout string
MsgBox "data recived:" & SCKdatatype
qudata = qudata & "-" & bytesTotal
If bolConnecting = True Then
If SCKdatatype = 5 Then
On Error Resume Next
''update server info
Call CopyMemory(VarPtr(serverINFO), StrPtr(strICStr), LenB(serverINFO))
ClientCMD.cmd = 1
ClientCMD.cmdtype = 0
buffer = Space(Len(ClientCMD))
''send cmd for recive myplayerinfo
Call CopyMemory(StrPtr(buffer), VarPtr(ClientCMD), LenB(ClientCMD))
strOutGoing = OGStr(10, buffer)
socket.SendData strOutGoing
bolConnecting = Not serverINFO.ConnAllowed
ElseIf serverINFO.ConnAllowed And SCKdatatype = 1 Then
''update myplaywer
On Error Resume Next
Call CopyMemory(VarPtr(MyPlayer), StrPtr(strICStr), LenB(MyPlayer))
bolConnecting = Not serverINFO.ConnAllowed
End If
Else
SCKdatatype = ICStr(strICStr, 1) ''data type
strICStr = ICStr(strICStr, 0) ''get string
Select Case SCKdatatype
Case 1
''update myplayer
On Error Resume Next
Call CopyMemory(VarPtr(MyPlayer), StrPtr(strICStr), LenB(MyPlayer))
Case 2
''msg game
On Error Resume Next
Call CopyMemory(VarPtr(GetMsg), StrPtr(strICStr), LenB(GetMsg))
Case 3
''player info
Case 4
''interface cmds
Case 5
''server data (only when connecting or changing acctype)
Case 6
''adduser
Case 7
''remuve user
Case 8
''update user
Case 9
End Select
End If
strICStr = ""
End Sub
Dim utypeClientInfo As CLIENTINFO_TYPE
With utypeClientInfo
.blowfish = " "
.checksum = "test"
.ver = "0001"
End With
strOutGoing = Space(LenB(utypeClientInfo))
Call CopyMemory(StrPtr(strOutGoing), VarPtr(utypeClientInfo), LenB(utypeClientInfo))
sending = True
bolConnecting = True
socket.SendData OGStr(0, strOutGoing)
strOutGoing = ""
When is clicked button for start starts drawing loop and connect to server that loop is looping utill the client dont recives all myplayer data
Edit: Im using winsock component i dont know but i think this is problem
Re: Winsock API troubles (data send but not recived)
i really dont think there is a problem with winsock or sending data, i think the problem could be dealing the strings.. i dont know functions you use to handle the strings, but maybe they dont return the right string, but nullstring, and in the result you send/recieve nullstring..
Re: Winsock API troubles (data send but not recived)
sory i forget to said that the OGStr and ICStr are my functions but they are just for testing
i have to rewrite this functions becouse they were primary for other project
VB Code:
Public Function OGStr(tip As Integer, ByVal str As String) As String
Dim tipe As String
Select Case tip
Case 0
''client presentation
tipe = "G000"
Case 1
''client clientid
tipe = "G001"
Case 2
''msg game
tipe = "G002"
Case 3
''player info
tipe = "G003"
Case 4
''interface cmds
tipe = "G004"
Case 5
''server presentation
tipe = "G005"
Case 6
''adduser
tipe = "G006"
Case 7
''removeuser
tipe = "G007"
Case 8
''update user
tipe = "G008"
Case 9
''moving to...
tipe = "G009"
Case 10
''client or server cmd
tipe = "G010"
Case Else
''eror
tipe = "Err"
End Select
If tipe <> "Err" Then
OGStr = Chr(1) & tipe & str & Chr(23)
End If
End Function
Public Function ICStr(ByVal str As String, ByVal TyorStr As Byte) As String
Dim tip As String
Dim tipe As Integer
''str = Left(str, Len(str) - 1)
''str = Right(str, Len(str) - 1)
str = str
tip = Left(str, 4)
str = Right(str, Len(str) - 4)
If TyorStr = 1 Then
Select Case tip
Case "G000"
''client presentation
tipe = 0
Case "G001"
''client clientid
tipe = 1
Case "G002"
''msg game
tipe = 2
Case "G003"
''player info
tipe = 3
Case "G004"
''interface cmds
tipe = 4
Case "G005"
''server data (only when connecting or changing acctype)
tipe = 5
Case "G006"
''adduser
tipe = 6
Case "G007"
''remuve user
tipe = 7
Case "G008"
''update user
tipe = 8
Case "G009"
''moving to...
tipe = 9
Case "G010"
''client or server cmd
tipe = 10
Case Else
''eror
tipe = -1
End Select
ICStr = tipe
ElseIf TyorStr = 0 Then
ICStr = str
End If
End Function
I dont think my winsock sends null string becouse i save every string in file for debuging and there are all strings.
When i read them with other program they are fine with all data and they can be copy in to UDT with no missing data or errors :/