Java 版 (精华区)
发信人: DreamWeaver (小样儿的,我气不死你?), 信区: Java
标 题: 每日一题第三期参考答案
发信站: 哈工大紫丁香 (2002年08月20日19:38:50 星期二), 站内信件
/**
* TCPClient.java
*/
import java.io.*;
import java.net.*;
class TCPClient{
public static void main(String argv[])throws Exception{
String sentence;
String modifiedSentence;
BufferedReader inFromUser=new BufferedReader(new
InputStreamReader(System.in));
Socket clientSocket=new Socket("127.0.0.1",6789);
DataOutputStream outToServer=new DataOutputStream(
clientSocket.getOutputStream());
BufferedReader inFromServer=new BufferedReader(
new InputStreamReader(clientSocket.getInputStream()));
sentence=inFromUser.readLine();
outToServer.writeBytes(sentence+'\n');
modifiedSentence=inFromServer.readLine();
System.out.println("FROM SERVER:"+modifiedSentence);
clientSocket.close();
}
}
/**
* TCPServer.java
*/
import java.io.*;
import java.net.*;
class TCPServer{
public static void main(String argv[])throws Exception{
String clientSentence;
String capitalizedSentence;
ServerSocket welcomeSocket=new ServerSocket(6789);
while(true){
Socket connectionSocket=welcomeSocket.accept();
BufferedReader inFromClient=new BufferedReader(
new InputStreamReader(connectionSocket.getInputStream()));
DataOutputStream outToClient=new DataOutputStream(
connectionSocket.getOutputStream());
clientSentence=inFromClient.readLine();
capitalizedSentence=clientSentence.toUpperCase()+'\n';
outToClient.writeBytes(capitalizedSentence);
}
}
}
--
╔═══════════════════════════════════╗
║ 我已成为疯狂的海洋 ↗却高高挂在天上 ↗┐ ║
║ 她却是冷静的月光 ↗ 我不惜的伸手抓拿 ● ∕ ┼┐ ║
║ 她明明在我心中 ↗ 却生出些悲哀的空想 ㄨ ㄣ ︳ ║
║﹏ ﹏﹏﹏ ﹏ ﹏→→ ﹏﹏ ﹏﹏﹏ ﹏ ﹏ ﹏﹏﹏﹏ ﹏﹏∕﹏ ﹏﹏﹨ ╲﹏ ║
╚═══════════════════════════════════╝ 你看到我的妮妮了吗? Q_Q
※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: 202.118.239.4]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:7.735毫秒