我是套接字编程的新手,也是我的玩具' Server'我没有得到同伴的任何一句话:
<style>
.parent-div .A {
...
}
</style>
<div class="parent-div">
<div class=”A”>
<h1>some text right aligned</h1>
<p> some text left aligned</p>
</div>
<div>
为了完整性,这是客户端类:
public class Server {
private ServerSocket myServerSocket;
String messageFromClient=null;
private void startServer(){
try{
myServerSocket=new ServerSocket(2000);
int portUsed= myServerSocket.getLocalPort();
System.out.println(portUsed);
Socket mySocket=myServerSocket.accept();
System.out.println("accepted");
InputStreamReader streamFromClient = new InputStreamReader(mySocket.getInputStream());
BufferedReader streamReader= new BufferedReader(streamFromClient);
messageFromClient=streamReader.readLine();
System.out.println("current message:"+messageFromClient);
if(messageFromClient!=null){
PrintStream ps = new PrintStream(mySocket.getOutputStream());
ps.print("Thank you client, I gratefully received from your message-hi from server!");
}
}
catch(Exception e){
e.printStackTrace();
}
}
他们都有主要方法。非常感谢任何帮助,谢谢你!
答案 0 :(得分:0)
您需要使用println
而不是所有print
。作为解释,当您的服务器正在等待客户端永远不会发送的行结束字符时。当服务器发送消息时也是如此。