Java 我的客户机服务器套接字有问题,我对代码进行了编程,但当我将信息(作为客户机)输入控制台时,仍然没有发生任何事情

Java 我的客户机服务器套接字有问题,我对代码进行了编程,但当我将信息(作为客户机)输入控制台时,仍然没有发生任何事情,java,networking,Java,Networking,所以我面临的问题是,当我运行客户端并输入时,我按enter键什么都没有发生,它继续向下滚动,客户端必须输入信息,然后将其发送到服务器,服务器接收信息并将其添加到linkedlist,linkedlist在服务器类中初始化,之后,服务器执行CalculateShippingPrice并将包含价格的输出发送回客户端 类客户端 类服务器 代码中似乎有一些问题可以通过使用调试器来解决。一个问题是客户端正在收集和发送四行输入,而服务器只读取一行输入。我猜您可能想阅读服务器中的所有四行并删除ClientSe

所以我面临的问题是,当我运行客户端并输入时,我按enter键什么都没有发生,它继续向下滚动,客户端必须输入信息,然后将其发送到服务器,服务器接收信息并将其添加到linkedlist,linkedlist在服务器类中初始化,之后,服务器执行CalculateShippingPrice并将包含价格的输出发送回客户端

类客户端

类服务器


代码中似乎有一些问题可以通过使用调试器来解决。一个问题是客户端正在收集和发送四行输入,而服务器只读取一行输入。我猜您可能想阅读服务器中的所有四行并删除ClientSession

name=informclient.readLine; ItemWeight=inFromClient.readLine PickUpLocation=infomclient.readLine DistnationLocation=infomclient.readLine 此外,响应必须写入新行,否则缓冲区将不会刷新。这可以通过在服务器中添加新行来解决:

outToClient.WriteByteCapitalizedEntence+'\n';
使用调试器找出什么都没有发生的原因。public static void mainString argv[]引发异常-可能尝试捕获异常
        //class CLient
        import java.io.*; .
        import java.net.*;
        class TCPClient {
        public static void main(String argv[]) throws Exception
        {
        String name;
        String ItemWeight;
        String PickUpLocation;
        String DistnationLocation;

        String modifiedSentence;// price to be returned to client
        BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
        Socket clientSocket = new Socket("localhost" , 3333);
        DataOutputStream outToServer = new DataOutputStream( clientSocket.getOutputStream());
        BufferedReader inFromServer = new BufferedReader(new 
        InputStreamReader(clientSocket.getInputStream()));

        System.out.println("please enter your name,itemWeight,pick up location,Distnation 
        location:");

        name = inFromUser.readLine(); //reads name
        ItemWeight = inFromUser.readLine(); //reads ItemWeight 
        PickUpLocation = inFromUser.readLine(); //reads PickUpLocation 
        DistnationLocation = inFromUser.readLine(); //reads DistnationLocation 


        outToServer.writeBytes(name + '\n'); //writes to server
        outToServer.writeBytes(ItemWeight + '\n');//writes to server
        outToServer.writeBytes(PickUpLocation + '\n');//writes to server
        outToServer.writeBytes(DistnationLocation + '\n');//writes to server


        modifiedSentence = inFromServer.readLine();//price to get from server
        System.out.println("FROM SERVER: " + modifiedSentence);//prints price
        clientSocket.close();
        }
        } 
        import java.io.*;

        import java.net.*; 
        class TCPServer {
        public static void main(String argv[]) throws Exception
        {
        List<customer> Shipping = new LinkedList<customer>();//initializes linked list from from 
        type customer that has all attributes  
        String name;
        String ItemWeight;
        String PickUpLocation;
        String DistnationLocation;
        String ItemID;
        String clientSentence;
        String capitalizedSentence;
        ServerSocket welcomeSocket = new ServerSocket (3333);

        while(true) {
        Socket connectionSocket = welcomeSocket.accept();
        BufferedReader inFromClient = new BufferedReader(new 
        InputStreamReader(connectionSocket.getInputStream()));
        DataOutputStream outToClient = new DataOutputStream( connectionSocket.getOutputStream());
        clientSentence = inFromClient.readLine(); //reads input from client
        name = clientSentence;//input from client
        ItemWeight = clientSentence;//input from client
        PickUpLocation = clientSentence;//input from client
        DistnationLocation = clientSentence;//input from client


        Shipping.insert(new customer(name, ItemWeight , PickUpLocation 
        ,DistnationLocation));//inserts info from client to linkedList in server

        capitalizedSentence = 
        "your shipping price is :" + Shipping.CalculateShippingPrice(Shipping);// calculates price
        outToClient.writeBytes(capitalizedSentence);//shows output to client 
        }
        }
        }