我正在尝试在连接时从服务器向客户端发送“Hello”...服务器端程序运行正常,但客户端代码出现“数据未准备好读取”的问题
这些是我的代码...请帮助...
服务器端 :
import java.net.*;
import java.io.*;
public class ServerSide
{
public static void main(String args[])
{
try
{
ServerSocket ss = new ServerSocket(8888);
System.out.println("Waiting...");
Socket server=ss.accept();
PrintStream ps= new PrintStream(server.getOutputStream());
ps.print("Hello...");
ps.flush();
System.out.println("Data Sent...");
}
catch(Exception e)
{
System.out.println("Error : " + e.toString());
}
}
}
客户端 :
import java.net.*;
import java.io.*;
public class ClientSide
{
public static void main(String args[])
{
try
{
String str= new String();
Socket client=new Socket(InetAddress.getLocalHost(),8888);
BufferedReader br = new BufferedReader(new InputStreamReader(client.getInputStream()));
if(br.ready())
{
str=br.readLine();
System.out.println(str);
}
else
{
System.out.println("Data not ready to read from Stream");
}
}
catch(Exception e)
{
System.out.println("Error : " + e.toString());
}
}
}