using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace sock_user
{
public partial class Form1 : Form
{
private IPAddress myIP = IPAddress.Parse("172.16.5.25");
private IPEndPoint MyServer;
private Socket connectsock;
private bool check = true;
private System.ComponentModel.Container components = null; public Form1()
{
InitializeComponent();
this.btn_connection.Click += new System.EventHandler(this.btn_connection_Click);
this.btn_send.Click += new System.EventHandler(this.btn_send_Click);
this.btn_close.Click+=new EventHandler(this.btn_close_Click);
} protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
private void Form1_Load(object sender, EventArgs e)
{ } private void btn_connection_Click(object sender, EventArgs e)
{
try
{
myIP = IPAddress.Parse(txt_system.Text); }
catch
{
MessageBox.Show("对不起,你输入的IP地址不正确");
}
try
{
MyServer = new IPEndPoint(myIP, Int32.Parse(txt_ask.Text));
connectsock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
connectsock.Connect(MyServer);
Thread thread = new Thread(new ThreadStart(receive));
thread.Start();
}
catch(Exception ee)
{
MessageBox.Show(ee.Message);
} } private void btn_send_Click(object sender, EventArgs e)
{
try
{
Byte[] sendbyte = new Byte[64];
string send = richTextBox2.Text + "\r\n";
NetworkStream netstream = new NetworkStream(connectsock);
sendbyte = System.Text.Encoding.BigEndianUnicode.GetBytes(send.ToArray());
netstream.Write(sendbyte, 0, sendbyte.Length);
netstream.Flush();
}
catch
{
MessageBox.Show("连接没有建立!无法发送");
}
} private void btn_close_Click(object sender, EventArgs e)
{
try
{
connectsock.Close(); }
catch
{
MessageBox.Show("连接没有建立!断开无效!");
}
} private void receive()
{
while(true)
{
Byte[] Rec = new Byte[64];
NetworkStream netstream = new NetworkStream(connectsock);
netstream.Read(Rec,0,Rec.Length);
string RecMessage=System.Text.Encoding.BigEndianUnicode.GetString(Rec);
richTextBox1.AppendText(RecMessage+"\r\n");
}
}
}
}
中间 有好多问题,比如:
1:错误 2 类型“sock_user.Form1”已定义了一个名为“Dispose”的具有相同参数类型的成员 D:\Users\shenbao\sock_user\sock_user\Form1.cs 32 33 sock_user
2:错误 1 类型“sock_user.Form1”已经包含“components”的定义 D:\Users\shenbao\sock_user\sock_user\Form1.cs 22 49 sock_user
等等……,请大家帮我看看其中还有好多问题该怎么解决
解决方案 »
- listview 重画的问题
- C# 给文件和文件夹写保护
- 请教一个重绘操作的做法,以zedGraph为背景做GDI画图,重绘事件怎么处理
- javascript的问题:有关link的问题
- 注册dll ,它说("D:\program")失败,找不到指定的模块,是怎么回事?
- 十六进制数赋值到一个数组
- 请教下一般C#和ASP.NET面试的话大概问些什么?
- Linq怎样在数据表中新增列
- 请问C#中有没有象Vb中的with语句那样的语句吗?
- 在C#中动态加入控件后,如何为控件的事件编写代码以响应事件???????
- C#程序调用非托管 DLL 方法前加static是否会造成冲突
- catch (Exception ex)时,我怎么知道是哪行报错?
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}