要求实现客户向服务器传输任意一个字符串,服务器将收到的字符串变换成大写后传回客户。
//客户端:
package tcpClient;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.Socket;
public class tcpClient {
private static Socket clientSocket;
public static void main(String args[]) throws Exception {
String sentence; // 声明字符串变量用于存储字符串输入和传送
String modifiedSentence;// 从服务器得到,并送到用户标准输出
System.out.println("请输入要转换的字符串:");
clientSocket = new Socket("localhost", 8579); // clientSocket为定义的套接字
BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));// 创建inFromUser程序的输入流
DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());//将流连接到标准输入
BufferedReader inFromServer =new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));//连接套接字的输入流
sentence =