这是服务器上的代码(C#):
private void Form1_Load(object sender, EventArgs e)
{
Thread service = new Thread((ThreadStart)delegate
{
IPAddress localAddr = IPAddress.Parse("127.0.0.1");
TcpListener listener = new TcpListener(localAddr, 13235);
listener.Start();
Console.Write("Waiting for a connection... ");
TcpClient client = listener.AcceptTcpClient();
Console.WriteLine("Connected!");
NetworkStream str = client.GetStream();
byte[] bytes5 = new byte[client.ReceiveBufferSize];
str.Read(bytes5, 0, (int)client.ReceiveBufferSize);
string returndata = Encoding.UTF8.GetString(bytes5);
Console.WriteLine("ewwww hone :" + returndata);
label1.Text = returndata;
client.Close();
});
service.Start();
}
}
Java 客户端:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
DataOutputStream os = null;
DataInputStream is = null;
int port = 13235;
System.out.println("SocketClient initialized \n");
try {
InetAddress address = InetAddress.getByName("127.0.0.1");
Socket connection = new Socket(address, port);
os = new DataOutputStream(connection.getOutputStream());
is = new DataInputStream(connection.getInputStream());
os.writeBytes(jTextField1.getText());
System.out.println(jTextField1.getText());
}
catch (IOException f) {
System.out.println("IOException: " + f);
}
catch (Exception g) {
System.out.println("Exception: " + g);
}
}
我的程序只有在我第一次单击按钮时才能正常工作,但在那之后我什么也没有得到!知道如何解决它,或者有什么问题吗?我需要的是我点击那个按钮(在客户端)我需要在服务器端得到它......