【发布时间】:2020-07-21 02:54:26
【问题描述】:
我正在尝试为一个简单的游戏设置一个测试服务器,我正在学习一个教程 (https://www.youtube.com/watch?v=uh8XaC0Y5MA)。有问题的代码是:
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
namespace GameServer
{
class Client
{
public static int dataBufferSize = 4096;
public int id;
public TcpClient tcp;
public Client(int _clientId)
{
id = _clientId;
tcp = new TCP(id);
}
public class TCP
{
public TcpClient socket;
private readonly int id;
private NetworkStream stream;
private byte[] receiveBuffer;
public TCP(int _id)
{
id = _id;
}
}
}
}
每当我尝试运行程序时,由于这段代码(确切地说是“新 TCP(id)”部分),我会从标题中得到错误:
public Client(int _clientId)
{
id = _clientId;
tcp = new TCP(id);
}
据我了解,问题是我无法将自写代码转换为标准库,但我看不出这会是什么问题。 所以我的问题是:我可以使用转换或其他解决方案来解决我的问题。 先感谢您。 PS。如果您需要更多源代码,请写评论。
【问题讨论】: