Hallo,
Bei einem Versuch habe ich eine simple Connection per Socket aufgebaut, indem ich eine IP mit Port versuche per Socket zu verbinden! z.B. einen WebServer per IP oder Hostnamen. Jedoch bekomme ich immer die Exception zurück!
Socket-Verbindung:
C#-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19:
| string iptext = lIP.Text; string porttext = lPort.Text; Socket connection = null; try { IPAddress ip = IPAddress.Parse(iptext); IPEndPoint ipEnd = new IPEndPoint(ip, Convert.ToInt32(porttext)); connection = new Socket(ipEnd.AddressFamily, SocketType.Stream, ProtocolType.Tcp); connection.Connect(ipEnd); if (connection.Connected) { ConnectionTA.Text = "Connection with " + iptext + " on Port " + porttext + " established!"; connection.Close(); } } catch (Exception esc) { ConnectionTA.Text = "Exception:\r\n" + esc.Message; } |
Die Ip und den Port hole ich mir jeweils aus einer GUI. Jedoch jede Möglichkeit brachte mich immer zur Exception.
Ich möchte später dieses Socket benutzen, um PCs im Netzwerk miteineander zu verbinden.
Ich hoffe, dass jemand mir ein paar Tipps und verbesserungen zu den besagten Problemen geben kann.
MFG
Marcel