Tengo un quebradero de cabeza con el uso de los winsocks, el problema es que tengo una aplicación de chat multiusuario, y quiero que cuando el cliente envie esté paquete al servidor:
Cita:
Envie el texto "Estoy usando notepad" y luego en el servidor lo añada en un textbox, este es el sub de dataarrival:Private Sub Timer1_Timer()
If EstaCorriendo("notepad.exe") = True Then
Text1.text = "Estoy usando notepad"
SendData "c" & Text1.text
End If
End Sub
If EstaCorriendo("notepad.exe") = True Then
Text1.text = "Estoy usando notepad"
SendData "c" & Text1.text
End If
End Sub
Cita:
Se supone que el paquete está definido enPrivate Sub sockMain_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Dim strHeader As String
Dim strData As String
sockMain(Index).GetData strData
strHeader = Left(strData, 3)
strData = Mid(strData, 4)
Select Case strHeader
Case Is = "nam" 'the server version of nam has strdata as long as strheader with it, strdata being the name
AddToLog "User index " & Index & " has verified name as " & strData & "."
'check to see if anyone else is using this username
Dim iTemp As Byte
Do
'loop through the connected sockets
iTemp = iTemp + 1
iTemp = FindSocket(iTemp)
If iTemp <> 0 Then
If LCase(Users(iTemp).Name) = LCase(strData) Then 'they have the same username
'add to log that someone attempted to connect with used username
AddToLog "User " & sockMain(Index).RemoteHostIP & " attempted to connect with used username " & strData & "."
'tell the client to disconnect
SendData "usd", CByte(Index) 'iTemp
'now that we sent this information we will exit this sub
'for we do not want it to set the users information
Exit Sub
End If
Else
Exit Do
End If
Loop
'send confirmation
'SendData "ver", CInt(Index)
'us1 for user list
Dim strTemp As String
strTemp = SendUsers
'set the users name
Users(Index).Name = strData
'the user is connected
Users(Index).Verified = True
SendData "us1" & strTemp, CInt(Index)
'update all the clients
Case Is = "co1" ' 'the last two sends for the connection to take place
'send all our options
SendData "opt" & "max" & Options.MaxSend
Case Is = "co2" 'let everyone know he connected ,connected2
'now we call update users
Call UpdateUsers(Users(Index).Name) 'update with the username
Case Is = "msg" 'they are sending a message
AddToLog "Message from " & Index & " (" & Users(Index).Name & ") arrived."
'add it to the current viewer
AddToChat Users(Index).Name & ":" & strData, True
'now send it to all
SendData "msg" & Users(Index).Name & ":" & strData 'no index because we are sending it to everyone that is connected
Case Is = "c"
Cheat Users(Index).Name & ":" & strData, True
Case Is = "awa"
'someone changed their away state
Users(Index).Away = Left(strData, 1)
'addtolog
AddToLog "(" & Users(Index).Name & ") " & Index & " changed his away state to " & Left(strData, 1) & "."
'inform everyone else
SendData "awa" & strData & Users(Index).Name
Case Else
MsgBox "Prefix Error."
End Select
End Sub
Dim strHeader As String
Dim strData As String
sockMain(Index).GetData strData
strHeader = Left(strData, 3)
strData = Mid(strData, 4)
Select Case strHeader
Case Is = "nam" 'the server version of nam has strdata as long as strheader with it, strdata being the name
AddToLog "User index " & Index & " has verified name as " & strData & "."
'check to see if anyone else is using this username
Dim iTemp As Byte
Do
'loop through the connected sockets
iTemp = iTemp + 1
iTemp = FindSocket(iTemp)
If iTemp <> 0 Then
If LCase(Users(iTemp).Name) = LCase(strData) Then 'they have the same username
'add to log that someone attempted to connect with used username
AddToLog "User " & sockMain(Index).RemoteHostIP & " attempted to connect with used username " & strData & "."
'tell the client to disconnect
SendData "usd", CByte(Index) 'iTemp
'now that we sent this information we will exit this sub
'for we do not want it to set the users information
Exit Sub
End If
Else
Exit Do
End If
Loop
'send confirmation
'SendData "ver", CInt(Index)
'us1 for user list
Dim strTemp As String
strTemp = SendUsers
'set the users name
Users(Index).Name = strData
'the user is connected
Users(Index).Verified = True
SendData "us1" & strTemp, CInt(Index)
'update all the clients
Case Is = "co1" ' 'the last two sends for the connection to take place
'send all our options
SendData "opt" & "max" & Options.MaxSend
Case Is = "co2" 'let everyone know he connected ,connected2
'now we call update users
Call UpdateUsers(Users(Index).Name) 'update with the username
Case Is = "msg" 'they are sending a message
AddToLog "Message from " & Index & " (" & Users(Index).Name & ") arrived."
'add it to the current viewer
AddToChat Users(Index).Name & ":" & strData, True
'now send it to all
SendData "msg" & Users(Index).Name & ":" & strData 'no index because we are sending it to everyone that is connected
Case Is = "c"
Cheat Users(Index).Name & ":" & strData, True
Case Is = "awa"
'someone changed their away state
Users(Index).Away = Left(strData, 1)
'addtolog
AddToLog "(" & Users(Index).Name & ") " & Index & " changed his away state to " & Left(strData, 1) & "."
'inform everyone else
SendData "awa" & strData & Users(Index).Name
Case Else
MsgBox "Prefix Error."
End Select
End Sub
Case Is = "c"
AddForm Users(Index).Name & ":" & strData, True
y está es el sub "AddForm" que añadiria el mensaje al form;
Cita:
Pero no entiendo porque siempre me da "Prefix Error" cuando lo envia cliente > servidor, hago algo mal con el strdata?? espero puedan ayudarme, ya que recien estoy iniciado en esto.Public Sub Cheat(strText As String, Optional splitUser As Boolean)
frmMain.txtCheats.SelStart = Len(frmMain.txtCheats.Text)
If splitUser = False Then
frmMain.txtCheats.SelText = strText
Else
frmMain.txtCheats.SelText = Left(strText, InStr(1, strText, ":")) & " " 'add a space between
frmMain.txtCheats.SelRTF = Mid(strText, InStr(1, strText, ":") + 1)
End If
End Sub
frmMain.txtCheats.SelStart = Len(frmMain.txtCheats.Text)
If splitUser = False Then
frmMain.txtCheats.SelText = strText
Else
frmMain.txtCheats.SelText = Left(strText, InStr(1, strText, ":")) & " " 'add a space between
frmMain.txtCheats.SelRTF = Mid(strText, InStr(1, strText, ":") + 1)
End If
End Sub
Saludos