sockets!!
-
I'm trying to make a program that sends data to another computer throught a net. I have follow an example but I can not establish connection. In the sender, I have this code:
'CREAR EL SOCKET Y CONECTAR Dim iphe As IPHostEntry = Nothing iphe = Dns.Resolve(server) Dim ipad As IPAddress = iphe.AddressList(0) ipad = iphe.AddressList(0) Dim ipe As New IPEndPoint(ipad, port) Dim tmpS As New Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp) tmpS.Connect(ipe) '****************************************** 'ENVIAR Dim ASCII As Encoding = Encoding.ASCII Dim envio As String = Me.txtAccion.Text Dim ByteGet As [Byte]() = ASCII.GetBytes(envio) Dim RecvBytes(255) As [Byte] Dim strRetPage As [String] = Nothing tmpS.Send(ByteGet, ByteGet.Length, 0)
And in the client pc I have this code:'CREAR EL SOCKET Y CONECTAR Dim iphe As IPHostEntry = Nothing iphe = Dns.Resolve(server) Dim ipad As IPAddress = iphe.AddressList(0) ipad = iphe.AddressList(0) Dim ipe As New IPEndPoint(ipad, port) Dim tmpS As New Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp) tmpS.Connect(ipe) '****************************************** 'RECIBIR Dim ASCII As Encoding = Encoding.ASCII Dim [Get] As String = "GET / HTTP/1.1" + ControlChars.Cr + ControlChars.Lf + "Host: " + server + ControlChars.Cr + ControlChars.Lf + "Connection: Close" + ControlChars.Cr + ControlChars.Lf + ControlChars.Cr + ControlChars.Lf Dim ByteGet As [Byte]() = ASCII.GetBytes([Get]) Dim RecvBytes(255) As [Byte] Dim strRetPage As [String] = Nothing ' Receive the server home page content. Dim bytes As Int32 = tmpS.Receive(RecvBytes, RecvBytes.Length, 0) ' Read the first 256 bytes. strRetPage = strRetPage + ASCII.GetString(RecvBytes, 0, bytes) While bytes > 0 bytes = tmpS.Receive(RecvBytes, RecvBytes.Length, 0) strRetPage = strRetPage + ASCII.GetString(RecvBytes, 0, bytes) End While MessageBox.Show(strRetPage)
Maybe all the code is wrong (sure!). Someone can help me with this? Maybe there is an easy way to make this... I'm sure someone will teach me :)