日期:2014-05-17 浏览次数:20791 次
namespace SimpleServer
{
public partial class Form1 : Form
{
private Thread ListenerThread;
TcpListener tcpListener = null;
public Form1()
{
InitializeComponent();
ListenerThread = new Thread(new ThreadStart(ListenerThreadMethod));
ListenerThread.IsBackground = true;
ListenerThread.Start();
}
public void ListenerThreadMethod()
{
TcpClient tcpClient = null;
NetworkStream networkStream = null;
try
{
IPAddress ip = IPAddress.Parse("127.0.0.1");
tcpListener = new TcpListener(ip, 7777);
tcpListener.Start();
}
catch
{
MessageBox.Show("不能建立服务器");
}
while (true)
{
try
{
tcpClient = tcpListener.AcceptTcpClient();
//对收到的请求做处理
List<byte> reData = new List<byte>();
byte[] reDataBytes = new byte[tcpClient.ReceiveBufferSize];
int n = 0;