我正在创建一个简单的客户端服务器通信。但我无法在命令提示符中输入任何内容。 服务器代码
当我运行程序时,我无法在 cmd 中输入任何内容
import java.net.*;
import java.io.*;
public class Tests
{
public static void main(String args[])
{
try
{
ServerSocket server = new ServerSocket(3000);
Socket c = server.accept();
DataOutputStream out = new DataOutputStream(c.getOutputStream());
DataInputStream in = new DataInputStream(c.getInputStream());
DataInputStream console = new DataInputStream(System.in);
String input,output;
while (true)
{
input = in.readLine();
System.out.println("Client says: " + input);
output = console.readLine();
out.writeBytes(output+ '\n');
}
}
catch(IOException e)
{ System.out.println("IO Error in streams " + e); }
}
}
客户端代码
请帮我
import java.io.*;
import java.net.*;
public class Testc
{
public static void main(String[] args)
{
try
{
Socket client = new Socket("127.0.0.1", 3000);
DataOutputStream out = new DataOutputStream(client.getOutputStream());
DataInputStream in = new DataInputStream(client.getInputStream());
DataInputStream console = new DataInputStream(System.in);
System.out.println("Connected. Enter text:");
String input,output;
while (true)
{
input = in.readLine();
System.out.println("server says : "+ input);
output = console.readLine();
out.writeBytes(output + '\n');
}
}
catch (UnknownHostException e)
{ System.err.println("error"); }
catch (IOException e)
{ System.err.println("I/O error"); }
}
}