Typenkonventierung Fehlermeldung
-
Hallo zusammen.
Ich habe auf der MSDN Seite einen TCP Server gefunden
http://msdn.microsoft.com/de-de/library/system.net.sockets.tcplistener.accepttcpclient(v=vs.90).aspx
und wollte diesen kompilieren.
Doch ich erhalte die FehlermeldungCannot implicitly convert type System.Net.Sockets.TcpClient to System.Net.Sockets.Socket
Ich glaube der mag das AcceptTcpClient( ) nicht kann mir da einer weiterhelfen?
-
using System; using System.Text; using System.IO; using System.Net; using System.Net.Sockets; using System.Threading; public class TcpListenerSample { static void Main(string[] args) { try { // set the TcpListener on port 13000 int port = 13000; TcpListener server = new TcpListener(IPAddress.Any, port); // Start listening for client requests server.Start(); // Buffer for reading data byte[] bytes = new byte[1024]; string data; //Enter the listening loop while (true) { Console.Write("Waiting for a connection... "); // Perform a blocking call to accept requests. // You could also user server.AcceptSocket() here. TcpClient client = server.AcceptTcpClient(); Console.WriteLine("Connected!"); // Get a stream object for reading and writing NetworkStream stream = client.GetStream(); int i; // Loop to receive all the data sent by the client. i = stream.Read(bytes, 0, bytes.Length); while (i != 0) { // Translate data bytes to a ASCII string. data = System.Text.Encoding.ASCII.GetString(bytes, 0, i); Console.WriteLine(String.Format("Received: {0}", data)); // Process the data sent by the client. data = data.ToUpper(); byte[] msg = System.Text.Encoding.ASCII.GetBytes(data); // Send back a response. stream.Write(msg, 0, msg.Length); Console.WriteLine(String.Format("Sent: {0}", data)); i = stream.Read(bytes, 0, bytes.Length); } // Shutdown and end connection client.Close(); } } catch (SocketException e) { Console.WriteLine("SocketException: {0}", e); } Console.WriteLine("Hit enter to continue..."); Console.Read(); } }
-
Keine Ahnung was du gemacht hast, aber der Code aus der MSDN laeuft bei mir Einwandfrei.