-3
此代码有一个错误:method must have a return type
。我该如何解决它?C#代理窗体窗体应用程序
public Server()
{
}
误差以上
服务器字public void createListener()
{
TcpListener tcpListener = null;
IPAddress ipAddress = Dns.GetHostEntry("localhost").AddressList[0];
try
{
tcpListener = new TcpListener(ipAddress, 13);
tcpListener.Start();
output = "Waiting for a connection...";
}
catch (Exception e)
{
output = "Error: " + e.ToString();
MessageBox.Show(output);
}
while (true)
{
Thread.Sleep(10);
TcpClient tcpClient = tcpListener.AcceptTcpClient();
byte[] bytes = new byte[256];
NetworkStream stream = tcpClient.GetStream();
stream.Read(bytes, 0, bytes.Length);
SocketHelper helper = new SocketHelper();
helper.processMsg(tcpClient, stream, bytes);
}
}
我应该在哪里增加吗?
static void Main()
{
Application.Run(new Server());
}
'公共类服务器 { }' 需要说的是什么样的对象的'Server'是 此刻,你的代码是假设服务器是一种方法和上应该有一个返回类型。既然你在你的Main中调用'new Server()'并且得到错误请求返回类型,我假设你打算创建一个类对象,并且你没有在你的类文件顶部声明这个类 '公共服务器(){ } '会的工作,如果你正在使用它作为一个构造函数,但应该是: '公共类服务器 { 公共服务器(){ } // 其他方法 }' – Draken
如果您从此[链接](https://msdn.microsoft.com/zh-cn/library/bb397809(v = vs.90).aspx)复制代码,则必须将代码单独放入类。创建一个新类,将其命名为Server,然后将代码复制到其中。 – Han
我创建了3个类 –