Ver Mensaje Individual
  #6 (permalink)  
Antiguo 15/09/2008, 22:46
Avatar de moradazo
moradazo
 
Fecha de Ingreso: julio-2008
Ubicación: [email protected]
Mensajes: 355
Antigüedad: 16 años, 10 meses
Puntos: 2
Respuesta: Visual Basic 2005: Programa Chat

Hola, gracias por las respuestas, encontré este código:

Código PHP:
Imports System
Imports System
.Text
Imports System
.IO
Imports System
.Net
Imports System
.Net.Sockets
Imports Microsoft
.VisualBasic

Public Class GetSocket

    
Private Shared Function ConnectSocket(ByVal server As StringByVal port As Integer) As Socket
        Dim s 
As Socket Nothing
        Dim hostEntry 
As IPHostEntry Nothing
 
        hostEntry 
Dns.GetHostEntry(server)
        
Dim address As IPAddress

        
For Each address In hostEntry.AddressList
            Dim endPoint 
As New IPEndPoint(addressport)
            
Dim tempSocket As New Socket(endPoint.AddressFamilySocketType.StreamProtocolType.Tcp)

            
tempSocket.Connect(endPoint)

            If 
tempSocket.Connected Then
                s 
tempSocket
                
Exit For
            
End If
        
Next address

        
Return s
    End 
Function


    Private 
Shared Function SocketSendReceive(ByVal server As String_
    ByVal port 
As Integer) As String

        Dim ascii 
As Encoding Encoding.ASCII
        Dim request 
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 bytesSent 
As [Byte]() = ascii.GetBytes(request)
        
Dim bytesReceived(255) As [Byte]

        
Dim s As Socket ConnectSocket(serverport)

        If 
s Is Nothing Then
            
Return "Connection failed"
        
End If

        
s.Send(bytesSentbytesSent.Length0)

        
Dim bytes As Int32

        Dim page 
As [String] = "Default HTML page on " server ":" _
        
ControlChars.Cr ControlChars.Lf

        
Do
            
bytes s.Receive(bytesReceivedbytesReceived.Length0)
            
page page Encoding.ASCII.GetString(bytesReceived0bytes)
        
Loop While bytes 0

        
Return page
    End 
Function

    Public 
Overloads Shared Sub Main()
        
Main(System.Environment.GetCommandLineArgs())
    
End Sub


    
Private Overloads Shared Sub Main(ByVal args() As String)
        
Dim host As String
        Dim port 
As Integer 80

        
If args.Length 1 Then
            host 
Dns.GetHostName()
        Else
            
host args(1)
        
End If

        
Dim result As String SocketSendReceive(hostport)

        
Console.WriteLine(result)
    
End Sub
End 
Class 
Si alguien me puede ayudar que hace cada función más o menos, gracias!