namespace LAN
{
public partial class Form1 : Form
{
private DialogResult result;
private TcpListener tcpLister = new TcpListener(9988);
System.Threading.ThreadStart listenPort;
System.Threading.Thread lister;
public Thread th;
public Thread tj;
Thread l;
private System.Drawing.Icon Icon1, Icon2;
private string message;
private bool Nfirst = false;
public Form1()
{
InitializeComponent();
Icon1 = notif.Icon;
Icon2 = notify1.Icon;
this.MaximizeBox = false;
listenPort += new ThreadStart(this.listen);
lister = new Thread(listenPort);
} private void Form1_Load(object sender, EventArgs e)
{ IpClass ic = new IpClass();
this.label3.Text = ic.name();
this.label4.Text = ic.ipc();
this.label5.Text = ic.data();
this.textBox1.AppendText("正在监听...\r\n");
lister.Name = "监听本地端口";
lister.Start();
}
private void listen()
{
try
{
tcpLister.Start();
while (true)
{
//接受挂起的请求
Socket s = tcpLister.AcceptSocket();
Byte[] stream = new Byte[80];
int i = s.Receive(stream);
message= System.Text.Encoding.UTF8.GetString(stream);
this.textBox1.AppendText(message);
if (WindowState == FormWindowState.Minimized)
{
th = new Thread(new ThreadStart(So));
th.Start();
}
FlashWindow(Handle, true);
}
}
catch (System.Security.SecurityException)
{
MessageBox.Show("防火墙安全错误!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
catch (System.Exception)
{
//this.textBox1.AppendText("已停止监听!");
}
} private void abortLister(object sender, System.ComponentModel.CancelEventArgs e)
{
this.tcpLister.Stop();
}
//发送消息
[DllImport("user32.dll")]
public static extern bool FlashWindow(
IntPtr hWnd, // handle to window
bool bInvert // flash status
);
private void Send()
{
try
{
Nfirst = true;
string msg = this.label3.Text + " (" + System.DateTime.Now.ToString() + ")\r\n" + this.textBox2.Text + "\r\n";
TcpClient client = new TcpClient(this.listBox1.SelectedItem.ToString(),9988);
NetworkStream sendStream = client.GetStream();
StreamWriter writer = new StreamWriter(sendStream);
writer.Write(msg);
writer.Flush();
sendStream.Close();
client.Close();
this.textBox1.AppendText(msg);
this.textBox2.Clear();
}
catch (System.Exception)
{
this.textBox1.AppendText("目标计算机拒绝连接请求!\r\n");
}
}
private void button1_Click(object sender, EventArgs e)
{
if (this.textBox2.Text == "")
{
try
{
MessageBox.Show("不能发送空信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
catch
{
MessageBox.Show("不能发送空信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
else
{
this.Send();
}
}
private void notif_MouseDoubleClick(object sender, MouseEventArgs e)
{
this.Visible = true;
this.notif.Visible = false;
this.notif.Icon = Icon1;
this.WindowState = FormWindowState.Normal;
}
private void Form1_Resize(object sender, EventArgs e)
{
if (this.WindowState ==FormWindowState.Minimized)
{
this.WindowState = FormWindowState.Minimized;
this.Visible = false;
this.notif.Visible = true;
}
}
请问怎么改啊
{
public partial class Form1 : Form
{
private DialogResult result;
private TcpListener tcpLister = new TcpListener(9988);
System.Threading.ThreadStart listenPort;
System.Threading.Thread lister;
public Thread th;
public Thread tj;
Thread l;
private System.Drawing.Icon Icon1, Icon2;
private string message;
private bool Nfirst = false;
public Form1()
{
InitializeComponent();
Icon1 = notif.Icon;
Icon2 = notify1.Icon;
this.MaximizeBox = false;
listenPort += new ThreadStart(this.listen);
lister = new Thread(listenPort);
} private void Form1_Load(object sender, EventArgs e)
{ IpClass ic = new IpClass();
this.label3.Text = ic.name();
this.label4.Text = ic.ipc();
this.label5.Text = ic.data();
this.textBox1.AppendText("正在监听...\r\n");
lister.Name = "监听本地端口";
lister.Start();
}
private void listen()
{
try
{
tcpLister.Start();
while (true)
{
//接受挂起的请求
Socket s = tcpLister.AcceptSocket();
Byte[] stream = new Byte[80];
int i = s.Receive(stream);
message= System.Text.Encoding.UTF8.GetString(stream);
this.textBox1.AppendText(message);
if (WindowState == FormWindowState.Minimized)
{
th = new Thread(new ThreadStart(So));
th.Start();
}
FlashWindow(Handle, true);
}
}
catch (System.Security.SecurityException)
{
MessageBox.Show("防火墙安全错误!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
catch (System.Exception)
{
//this.textBox1.AppendText("已停止监听!");
}
} private void abortLister(object sender, System.ComponentModel.CancelEventArgs e)
{
this.tcpLister.Stop();
}
//发送消息
[DllImport("user32.dll")]
public static extern bool FlashWindow(
IntPtr hWnd, // handle to window
bool bInvert // flash status
);
private void Send()
{
try
{
Nfirst = true;
string msg = this.label3.Text + " (" + System.DateTime.Now.ToString() + ")\r\n" + this.textBox2.Text + "\r\n";
TcpClient client = new TcpClient(this.listBox1.SelectedItem.ToString(),9988);
NetworkStream sendStream = client.GetStream();
StreamWriter writer = new StreamWriter(sendStream);
writer.Write(msg);
writer.Flush();
sendStream.Close();
client.Close();
this.textBox1.AppendText(msg);
this.textBox2.Clear();
}
catch (System.Exception)
{
this.textBox1.AppendText("目标计算机拒绝连接请求!\r\n");
}
}
private void button1_Click(object sender, EventArgs e)
{
if (this.textBox2.Text == "")
{
try
{
MessageBox.Show("不能发送空信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
catch
{
MessageBox.Show("不能发送空信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
else
{
this.Send();
}
}
private void notif_MouseDoubleClick(object sender, MouseEventArgs e)
{
this.Visible = true;
this.notif.Visible = false;
this.notif.Icon = Icon1;
this.WindowState = FormWindowState.Normal;
}
private void Form1_Resize(object sender, EventArgs e)
{
if (this.WindowState ==FormWindowState.Minimized)
{
this.WindowState = FormWindowState.Minimized;
this.Visible = false;
this.notif.Visible = true;
}
}
请问怎么改啊
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货