c#

你的选择B 2010-07-25 10:19:14

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
等等……,请大家帮我看看其中还有好多问题该怎么解决
...全文
57 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
兔子-顾问 2010-07-25
  • 打赏
  • 举报
回复
按错误提示,删除如下内容:

private System.ComponentModel.Container components = null;

protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
mayonglong 2010-07-25
  • 打赏
  • 举报
回复
你的窗口是不是复制的,可能名字没有修改,相同命名空间下类名相同~
萨拉嘿 2010-07-25
  • 打赏
  • 举报
回复
双击错误提示。。修改。。
Thr21ough 2010-07-25
  • 打赏
  • 举报
回复
up~

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧