就是本人先在comboBox选择一项,然后通过按下按钮,把选择的那一项内容通过socket来发送到服务器,本人就不太清楚应该做,下面是代码。
namespace win1
{
public partial class Form1 : Form
{
public static void main(String[] args)
{
ClientMethod();
}
public static void ClientMethod()
{
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPAddress myIP = IPAddress.Parse(“223.3.110.26”);
IPEndPoint EPhost = new IPEndPoint(myIP, int.Parse(“1234”));
socket.Connect(EPhost);
string str = Console.ReadLine();
Console.ReadLine();
byte[] sendBytes = System.Text.Encoding.Default.GetBytes(str + “\r”);
socket.Send(sendBytes, sendBytes.Length, SocketFlags.None);
socket.Send(Encoding.ASCII.GetBytes(“123”));
byte[] buf = new byte[256];
socket.Receive(buf);
string s = System.Text.Encoding.Default.GetString(buf);
Console.WriteLine(s);
socket.Close();
}
public Form1()
{
InitializeComponent();
ClientMethod();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
ClientMethod();
byte[] str = Encoding.Default.GetBytes(this.comboBox1.Text);
textBox1.Text = this.comboBox1.Text;
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}
namespace win1
{
public partial class Form1 : Form
{
public static void main(String[] args)
{
ClientMethod();
}
public static void ClientMethod()
{
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPAddress myIP = IPAddress.Parse(“223.3.110.26”);
IPEndPoint EPhost = new IPEndPoint(myIP, int.Parse(“1234”));
socket.Connect(EPhost);
string str = Console.ReadLine();
Console.ReadLine();
byte[] sendBytes = System.Text.Encoding.Default.GetBytes(str + “\r”);
socket.Send(sendBytes, sendBytes.Length, SocketFlags.None);
socket.Send(Encoding.ASCII.GetBytes(“123”));
byte[] buf = new byte[256];
socket.Receive(buf);
string s = System.Text.Encoding.Default.GetString(buf);
Console.WriteLine(s);
socket.Close();
}
public Form1()
{
InitializeComponent();
ClientMethod();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
ClientMethod();
byte[] str = Encoding.Default.GetBytes(this.comboBox1.Text);
textBox1.Text = this.comboBox1.Text;
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}
解决方案
5
首先不是很明白LZ的意思。
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { //这里写你需要执行的代码;就可以了。 }
15
http://download.csdn.net/album/detail/631
http://blog.sina.com.cn/s/blog_76b5256c0100wz7c.html
http://blog.sina.com.cn/s/blog_76b5256c0100wz7c.html