hacer un socket cliente

01/10/2004 - 09:59 por antonio | Informe spam
Hola a todos.
Estoy intentando crear una aplicacion cliente que se
conecte a maquinas remotas usando sockets.

El caso es que consigo conectarme y recibir una cadena de
caracteres del servidor, pero cuando a continuacion
intento mandarle informacion, me parece que no lo consigo,
ya que al volver a recibir, recibo lo que yo he mandado y
no la respuesta a mi orden.

¿Que estoy haciendo mal?. Se supone que con socket.receive
puedes recibir lo que te mande el servidor. De hecho la
primera vez lo consigo, pero luego ya no.

Aqui esta el codigo
Dim ip As IPAddress = ip.Parse("xxx.xxx.xxx.xxx")
Dim algo As New IPEndPoint(ip, 23)
Dim s As New Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp)
Dim strRetPage As String
Dim RecvBytes(256) As Byte

s.Connect(algo)
dim bytes As Int32 = s.Receive(RecvBytes,
RecvBytes.Length, 0)

If bytes > 0 Then
TextBox1.Text = TextBox1.Text &
Encoding.ASCII.GetString(RecvBytes, 0, bytes) & vbCrLf
End If

strRetPage = Microsoft.VisualBasic.Left
(TextBox1.Text, 6)
If strRetPage = ">login" Then
login= "XXXXXXXXXXXX"
Dim ByteGet As Byte() = Encoding.ASCII.GetBytes
(login)
Dim bytesend As Integer = s.Send(ByteGet,
login.Length, SocketFlags.None)
End If

While Not strRetPage = "ENTER USER NAME"
bytes = s.Receive(RecvBytes)
If bytes > 0 Then ; EN ESTE PUNTO SOLO RECIBO
UN BYTE CADA VEZ Y ES CADA UNO DE LOS CARACTERES QUE HE
MANDADO EN LOGIN
TextBox1.Text = TextBox1.Text &
Encoding.ASCII.GetString(RecvBytes, 0, bytes) & vbCrLf
End If

End While

Gracias por anticipado
antonio
 

Leer las respuestas

#1 DJMIAO
02/10/2004 - 00:24 | Informe spam
Miao...
Comprate un libro...
Hola a todos.
Estoy intentando crear una aplicacion cliente que se
conecte a maquinas remotas usando sockets.

El caso es que consigo conectarme y recibir una cadena


de
caracteres del servidor, pero cuando a continuacion
intento mandarle informacion, me parece que no lo


consigo,
ya que al volver a recibir, recibo lo que yo he mandado


y
no la respuesta a mi orden.

¿Que estoy haciendo mal?. Se supone que con


socket.receive
puedes recibir lo que te mande el servidor. De hecho la
primera vez lo consigo, pero luego ya no.

Aqui esta el codigo
Dim ip As IPAddress = ip.Parse("xxx.xxx.xxx.xxx")
Dim algo As New IPEndPoint(ip, 23)
Dim s As New Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp)
Dim strRetPage As String
Dim RecvBytes(256) As Byte

s.Connect(algo)
dim bytes As Int32 = s.Receive(RecvBytes,
RecvBytes.Length, 0)

If bytes > 0 Then
TextBox1.Text = TextBox1.Text &
Encoding.ASCII.GetString(RecvBytes, 0, bytes) & vbCrLf
End If

strRetPage = Microsoft.VisualBasic.Left
(TextBox1.Text, 6)
If strRetPage = ">login" Then
login= "XXXXXXXXXXXX"
Dim ByteGet As Byte() =


Encoding.ASCII.GetBytes
(login)
Dim bytesend As Integer = s.Send(ByteGet,
login.Length, SocketFlags.None)
End If

While Not strRetPage = "ENTER USER NAME"
bytes = s.Receive(RecvBytes)
If bytes > 0 Then ; EN ESTE PUNTO SOLO


RECIBO
UN BYTE CADA VEZ Y ES CADA UNO DE LOS CARACTERES QUE HE
MANDADO EN LOGIN
TextBox1.Text = TextBox1.Text &
Encoding.ASCII.GetString(RecvBytes, 0, bytes) & vbCrLf
End If

End While

Gracias por anticipado
antonio
.

Preguntas similares