Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 什么是TCP上的固定长度?_Java_Sockets_Networking_Tcp - Fatal编程技术网

Java 什么是TCP上的固定长度?

Java 什么是TCP上的固定长度?,java,sockets,networking,tcp,Java,Sockets,Networking,Tcp,我的情景 我不熟悉基于套接字的编程或TCP之类的网络协议。我有一个服务器,它基于TCP上的固定长度协议工作。我有一个示例客户端应用程序,它读取TXT文件并通过套接字将其发送到服务器 我试图用一个简单的应用程序复制服务器,该应用程序通过套接字接收来自客户端的请求并响应客户端 下面提到了我的客户机和服务器应用程序 客户端代码 这很好用 我的问题是 我实现的是TCP上的固定长度?如果没有,如何为相同的应用程序实现示例客户机和服务器java应用程序 TCP上的固定长度与我实现的有什么不同 摆脱现成的测试

我的情景

我不熟悉基于套接字的编程或TCP之类的网络协议。我有一个服务器,它基于TCP上的固定长度协议工作。我有一个示例客户端应用程序,它读取TXT文件并通过套接字将其发送到服务器

我试图用一个简单的应用程序复制服务器,该应用程序通过套接字接收来自客户端的请求并响应客户端

下面提到了我的客户机和服务器应用程序

客户端代码

这很好用

我的问题是

我实现的是TCP上的固定长度?如果没有,如何为相同的应用程序实现示例客户机和服务器java应用程序

TCP上的固定长度与我实现的有什么不同


摆脱现成的测试。这是毫无意义的。以下读数将根据需要被阻止。@EJP,您能详细说明一下吗?
 String host = "localhost";

        int port = 19997;

    StringBuffer instr = new StringBuffer();
    String TimeStamp;
    System.out.println("SocketClient initialized");

    try {
      InetAddress address = InetAddress.getByName(host);
      Socket connection = new Socket(address, port);

       BufferedOutputStream bos = new BufferedOutputStream(connection.
          getOutputStream());
      OutputStreamWriter osw = new OutputStreamWriter(bos, "US-ASCII");

      TimeStamp = new java.util.Date().toString();

      String process = "01234"+  (char) 13;

      osw.write(process);
      osw.flush();

      BufferedInputStream bis = new BufferedInputStream(connection.
          getInputStream());

      InputStreamReader isr = new InputStreamReader(bis, "US-ASCII");

      int c,d=0;
      try
      {
          if(isr.ready())
          {
          }
          else
              System.out.println("NO RESPONSE");
      while (( (c = isr.read()) != 13) && d<4)
      {
        instr.append( (char) c);
        System.out.println("Inside Loop - "+instr);
        d++;
      }}
      catch(OutOfMemoryError e)
      {
          System.out.println("OOM ERROR - "+e);
          System.out.println(instr);
      }
      /** Close the socket connection. */
      connection.close();
      System.out.println(instr);

    }
    catch(UnknownHostException e)
    {
     System.out.println("Unknown Host Exception: " + e);
    }
    catch(ConnectException e)
    {
     System.out.println("ConnectException: " + e);
    }
    catch(Exception e1)
    {
     System.out.println("Exception: " + e1);
    } 
        try{
      socket1 = new ServerSocket(port);
      System.out.println("SingleSocketServer Initialized");
      int character;

    while (true) {
        connection = socket1.accept();

        BufferedInputStream is = new BufferedInputStream(connection.getInputStream());
        InputStreamReader isr = new InputStreamReader(is);
        process = new StringBuffer();
        while((character = isr.read()) != 13) {
          process.append((char)character);
          System.out.println("Inside while loop");
        }
        System.out.println("Hello"+process);
        //need to wait 10 seconds for the app to update database
        try {
          Thread.sleep(10000);
        }
        catch (Exception e){}
        TimeStamp = new java.util.Date().toString();
        //String returnCode = "SingleSocketServer repsonded at "+ TimeStamp + (char) 13;
        String returnCode = "56789"+  (char) 13;
        BufferedOutputStream os = new BufferedOutputStream(connection.getOutputStream());
        OutputStreamWriter osw = new OutputStreamWriter(os, "US-ASCII");
        osw.write(returnCode);
        osw.flush();
     }
    }
    catch (IOException e) {}
      try {
        connection.close();
      }
      catch (IOException e) {}
  }