【发布时间】:2010-06-27 17:19:06
【问题描述】:
我正在开发一个在局域网中工作的加密聊天程序,它也应该能够发送文件。问题如下: 1-对于聊天部分它只发送1条消息并关闭连接,对方应该再次运行程序以接收更多消息,我试图把它放在这样的循环中 (receive close 再receive),但是程序崩溃了,
我在接收文件时遇到同样的问题,
知道如何解决这个问题吗?
这是代码
IP = textBox2.Text.ToString();
int 端口 = int.Parse(textBox1.Text);
IPAddress IP2 = IPAddress.Parse(IP);
TcpListener TCPListen = new TcpListener(IP2, port);
TCPListen.Start();
TcpClient TCP = TCPListen.AcceptTcpClient();
//bool a = false;
NetworkStream NetStream = TCP.GetStream();
//while (!a)
//{
RijndaelManaged RMCrypto = new RijndaelManaged();
byte[] Key = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 };
byte[] IV = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 };
CryptoStream CryptStream = new CryptoStream(NetStream,
RMCrypto.CreateDecryptor(Key, IV),
CryptoStreamMode.Read);
StreamReader SReader = new StreamReader(CryptStream);
message = SReader.ReadToEnd();
textBox3.Clear();
textBox3.Text = message;
CryptStream.Flush();
SReader.Close();
//encryption(NetStream);
NetStream.Flush();
NetStream.Close();
TCPListen.Stop();
TCP.Close();
而且它在一个循环中 布尔 a = 假; while(!a) 表示持续执行。
【问题讨论】:
-
我们需要更具体的信息。程序如何崩溃?崩溃的代码是什么?
-
我不能把它作为命令,所以将编辑问题并把它放在那里。
-
这是从客户端接收加密数据的服务器,如果您需要其他任何内容,请告诉我。
标签: c#