Foros del Web » Programación para mayores de 30 ;) » Programación General » Visual Basic clásico »

Dua/Problema con Winsock

Estas en el tema de Dua/Problema con Winsock en el foro de Visual Basic clásico en Foros del Web. Hola a todos. Tengo un quebradero de cabeza con el uso de los winsocks, el problema es que tengo una aplicación de chat multiusuario, y ...
  #1 (permalink)  
Antiguo 21/11/2009, 08:05
 
Fecha de Ingreso: enero-2009
Mensajes: 20
Antigüedad: 15 años, 4 meses
Puntos: 0
Pregunta Dua/Problema con Winsock

Hola a todos.

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:
Private Sub Timer1_Timer()
If EstaCorriendo("notepad.exe") = True Then
Text1.text = "Estoy usando notepad"
SendData "c" & Text1.text
End If
End Sub
Envie el texto "Estoy usando notepad" y luego en el servidor lo añada en un textbox, este es el sub de dataarrival:

Cita:
Private 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
Se supone que el paquete está definido en

Case Is = "c"
AddForm Users(Index).Name & ":" & strData, True

y está es el sub "AddForm" que añadiria el mensaje al form;

Cita:
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
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.

Saludos
  #2 (permalink)  
Antiguo 21/11/2009, 08:17
Avatar de pkj
pkj
 
Fecha de Ingreso: julio-2006
Ubicación: Órbita sincrónica
Mensajes: 899
Antigüedad: 17 años, 9 meses
Puntos: 29
Respuesta: Dua/Problema con Winsock

El problema lo tienes en el encabezado que has elegido.

No puedes usar "C" como encabezado porque el encabezado debe tener 3 caracteres.

Cambia "c" por "cxx" en ambos sitios y debería funcionar si lo demas lo tienes bien.
__________________
No hay preguntas tontas, solo gente estup..., ¡No!, ¿como era? No hay gente que pregunte a tontos... ¡Nooo!... ¡Vaya cabeza!
  #3 (permalink)  
Antiguo 21/11/2009, 09:00
 
Fecha de Ingreso: enero-2009
Mensajes: 20
Antigüedad: 15 años, 4 meses
Puntos: 0
Respuesta: Dua/Problema con Winsock

Vale, muchas gracias, y funciona todo perfectamente.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 18:25.