Aiuto visual basic tcpclient

di il
6 risposte

Aiuto visual basic tcpclient

Buona sera a tutti,
volevo realizzare un proxy server in vb.net(2010) ma ho riscontrato un problema:
quando connetto un client il server lo riconosce ma sul client non c'è la connessione internet (il client è un dispositivo esterno es. iphone psp ps3 pc)
Avete percaso qualche soluzione?
vi posto il codice.
Imports System.Net
Imports System.Net.Sockets

Public Class Form1
    Dim a As Int32
    Dim b As IPAddress

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        TextBox4.Text = "Proxy Disabilitato"
        label6.Text = "Connessione terminata..."
        a = TextBox1.Text
        b = IPAddress.Parse(TextBox2.Text)
        Dim tcpListener As New TcpListener(b, a)
        tcpListener.Stop()
        Button2.Visible = False
        Button3.Visible = True
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim sam As System.Net.IPAddress
        Dim sam1 As String
        With System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName())
            sam = New System.Net.IPAddress(.AddressList(0).Address)
            sam1 = sam.ToString
        End With
        TextBox2.Text = sam1
        TextBox1.Text = "8080"
        Button2.Visible = False
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        a = TextBox1.Text
        b = IPAddress.Parse(TextBox2.Text)
        TextBox4.Text = "Proxy Abilitato"
        Button2.Visible = True
        Button3.Visible = False
        Dim tcpListener As New TcpListener(b, a)
        tcpListener.Start()
        label6.Text = "Attendo..."
        Try           
            Dim tcpClient As TcpClient = tcpListener.AcceptTcpClient()
            label6.Text = "Connessione stabilita."
            Dim networkStream As NetworkStream = tcpClient.GetStream()
            Dim bytes(tcpClient.ReceiveBufferSize) As Byte
            networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
            Dim clientdata As String = System.Text.Encoding.ASCII.GetString(bytes)
            label6.Text = ("Client sent: " + clientdata)
            Dim responseString As String = "Connesso al server"
            Dim sendBytes As [Byte]() = System.Text.Encoding.ASCII.GetBytes(responseString)
            networkStream.Write(sendBytes, 0, sendBytes.Length)
            label6.Text = ("Message Sent /> : " + responseString)
            tcpClient.Close()
            tcpListener.Stop()
            label6.Text = "exit"
        Catch ex As Exception
            label6.Text = ex.ToString()
        End Try
    End Sub
End Class

6 Risposte

Devi accedere o registrarti per scrivere nel forum
6 risposte