已经坐了一个小时的代码,我什么都没想。疲劳的。
我有一堂课:
class ConnectionThread
{
public TcpListener threadListener;
public ConnectionThread(TcpListener lis)
{
threadListener = lis;
ThreadPool.QueueUserWorkItem(new WaitCallback(HandleConnection));
}
public void HandleConnection(object state)
{
TcpClient client = threadListener.AcceptTcpClient();
Byte[] bytes = new Byte[25600000];
String data = null;
NetworkStream stream = client.GetStream();
int i;
while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
{
// I WANT INCLUDE HERE CODE OUT OF CLASS!!!
}
stream.Close();
client.Close();
}
}
如果我的课程在附加文件中,那么在 while 循环中包含代码的更好方法是什么?例如在 while 中包含这个:
data = System.Text.Encoding.Default.GetString(bytes, 0, i);
MessageBox.Show("Received: " + data);
data = data.ToUpper();
byte[] msg = System.Text.Encoding.Default.GetBytes(data);
stream.Write(msg, 0, msg.Length);
MessageBox.Show("Sent: " + data);