DREvil1993
Grünschnabel
Hallo wie die Überschrift schon sagt hab ich nen Problem mit einen Chatprogramm das ich mit Socket gemacht hab.
Im eigenen Netzwerk t alles wunderbar. Allerdings hab ich das Problem, dass wenn ich versuche von einem anderen Computer aus zu verbinden, der Server nicht reagiert.
Im eigenen Netzwerk t alles wunderbar. Allerdings hab ich das Problem, dass wenn ich versuche von einem anderen Computer aus zu verbinden, der Server nicht reagiert.
Code:
Imports System.Net.Sockets
Imports System.Text
Imports System.IO
Imports System.Net
Public Class Form1
Private SimpleServer As TcpListener
Private Client As New TcpClient
Private Stream As NetworkStream
Dim bytes() As Byte
Private Sub OnConnect(ByVal ar As System.IAsyncResult)
Client = SimpleServer.EndAcceptTcpClient(ar)
Stream = Client.GetStream
ReDim bytes(Client.ReceiveBufferSize)
Stream.BeginRead(bytes, 0, CInt(Client.ReceiveBufferSize), AddressOf onGetData, New Object)
End Sub
Private Sub onGetData(ByVal ar As System.IAsyncResult)
Dim clientdata As String = Encoding.ASCII.GetString(bytes)
Try
Stream.BeginRead(bytes, 0, CInt(Client.ReceiveBufferSize), AddressOf onGetData, New Object)
MsgBox(clientdata, 0, "")
Catch
MsgBox("Verbindung unterbrochen", 0, "")
SimpleServer.BeginAcceptTcpClient(AddressOf OnConnect, New Object)
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
NumericUpDown1.Enabled = False
SimpleServer = New TcpListener(System.Net.IPAddress.Parse(0), NumericUpDown1.Value)
SimpleServer.Start()
SimpleServer.BeginAcceptTcpClient(AddressOf OnConnect, New Object)
Label1.BackColor = Color.Lime
Label1.Text = "ONLINE"
RichTextBox1.Text &= "Server ist Online..." & vbCrLf
Try
Dim req As HttpWebRequest = WebRequest.Create("http://whatismyip.com/automation/n09230945.asp")
Dim res As HttpWebResponse = req.GetResponse()
Dim Str As Stream = res.GetResponseStream()
Dim sr As StreamReader = New StreamReader(Str)
RichTextBox1.Text &= "Internet IP = " & sr.ReadToEnd() & vbCrLf
Catch
RichTextBox1.Text &= "Internet IP = N/A" & vbCrLf
End Try
Button1.Enabled = False
End Sub
Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("admin : " & TextBox1.Text)
Stream.Write(sendBytes, 0, sendBytes.Length)
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
ListView1.Items.Clear()
Dim ipend As Net.IPEndPoint = DirectCast(Client.Client.RemoteEndPoint, Net.IPEndPoint)
If Not ipend Is Nothing Then
ListView1.Items.Add(New ListViewItem(New String() {ipend.Address.ToString, ipend.Port.ToString}))
End If
End Sub
End Class