不显示删除回复显示所有回复显示星级回复显示得分回复 C# socket客户端程序一运行就卡住了,咋个回事啊???
这鬼程序一运行 按连接按钮后就卡卡卡卡卡卡卡死啦!也不知道咋回事!功能可不可实现!
哪位好心人帮忙研究下,作业马上要交了啊!1
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace mmysocket
{
public partial class Form1 : Form
{
Socket sock1;
bool flag = true;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
IPAddress HostIP = IPAddress.Parse("113.55.44.18");
try
{
IPEndPoint ipep = new IPEndPoint(HostIP, Int32.Parse("2011"));
sock1 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
sock1.Connect(ipep);
}
catch (Exception ey)
{
MessageBox.Show("服务器没有开启+\r\n" + ey.Message);
}
if(sock1.Connected)
while (flag)
{
byte[] bytes = new byte[1024];
sock1.Receive(bytes, bytes.Length, 0);
string str = Encoding.ASCII.GetString(bytes);
richTextBox1.Text += "client:" + str + "\r\n";
}
}
private void button2_Click(object sender, EventArgs e)
{
try
{
richTextBox1.Text += "client:" + richTextBox2.Text + "\r\n";
string m = richTextBox2.Text;
richTextBox2.Text = "";
byte[] byteData = new byte[1024];
string strsend = "client:" + m + "\r\n";
byteData = Encoding.ASCII.GetBytes(strsend.ToCharArray());
sock1.Send(byteData, byteData.Length, 0);
}
catch { }
}
private void button3_Click(object sender, EventArgs e)
{
Environment.Exit(Environment.ExitCode);
}
}
}