面试题Java 的通信编程,编程题(或问答),用JAVA SOCKET 编程,读服务器几个字符,再写入本地显示?
Posted 职英优就业
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了面试题Java 的通信编程,编程题(或问答),用JAVA SOCKET 编程,读服务器几个字符,再写入本地显示?相关的知识,希望对你有一定的参考价值。
我的写作,
不只是在告诉人关于这人间的美丽,而是在唤起一些沉睡着的美丽的心。
Java 的通信编程,编程题(或问答),用JAVA SOCKET 编程,读服务器几个字符,再写入本地显示?
答:Server 端程序:
packagetest;
importjava.net.*;
importjava.io.*;
publicclass Server{
privateServerSocket ss;
privateSocket socket;
privateBufferedReader in;
privatePrintWriter out;
publicServer(){
try{
ss=newServerSocket(10000);
while(true){
socket= ss.accept();
StringRemoteIP =
socket.getInetAddress().getHostAddress();
StringRemotePort = ":"+socket.getLocalPort();
System.out.println("Aclient come in!IP:"
+RemoteIP+RemotePort);
in= new BufferedReader(new
InputStreamReader(socket.getInputStream()));
Stringline = in.readLine();
System.out.println("Cleintsend is :" + line);
out=
newPrintWriter(socket.getOutputStream(),true);
out.println("YourMessage Received!");
out.close();
in.close();
socket.close();
}
}catch(IOException e){
out.println("wrong");
}
}
publicstatic void main(String[] args){
newServer();
}
}
Client端程序:
packagetest;
importjava.io.*;
importjava.net.*;
publicclass Client {
Socketsocket;
BufferedReaderin;
PrintWriterout;
publicClient(){
try{
System.out.println("Tryto Connect to
127.0.0.1:10000");
socket= new Socket("127.0.0.1",10000);
System.out.println("TheServer Connected!");
System.out.println("Pleaseenter some Character:");
BufferedReaderline = new BufferedReader(new
InputStreamReader(System.in));
out= new PrintWriter(socket.getOutputStream(),true);
out.println(line.readLine());
in= new BufferedReader(
newInputStreamReader(socket.getInputStream()));
System.out.println(in.readLine());
out.close();
in.close();
socket.close();
}catch(IOExceptione){
out.println("Wrong");
}
}
publicstatic void main(String[] args) {
newClient();
}
}
UML 是什么?常用的几种图?
答:UML 是标准建模语言;常用图包括:用例图,静态图(包括类图、对象图和包图),行为图,交互图(顺序图,合作图),实现图。
END
以上是关于面试题Java 的通信编程,编程题(或问答),用JAVA SOCKET 编程,读服务器几个字符,再写入本地显示?的主要内容,如果未能解决你的问题,请参考以下文章