Advertisement
Guest User

Untitled

a guest
Sep 4th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.88 KB | None | 0 0
  1. import java.net.*; // for Socket, ServerSocket, and InetAddress
  2. import java.io.*; // for IOException and Input/OutputStream
  3. import java.util.Scanner;
  4.  
  5. public class TCPEchoServer {
  6.        
  7.         private static final int BUFSIZE = 32;  // Size of receive buffer
  8.        
  9.         public static void main (String[] args) throws IOException {
  10.                
  11.                
  12.                 int servPort =  8000;
  13.                
  14.                 // Create a server socket to accept client connection requests
  15.                 ServerSocket servSock = new ServerSocket(servPort);
  16.                
  17.                 for (;;) { // Run forever, accpeting and servicing connections
  18.                         Socket clntSock = servSock.accept();  // Get client connection
  19.                        
  20.                         System.out.println ("Handling client at " +
  21.                           clntSock.getInetAddress().getHostAddress() + " on port " +
  22.                             clntSock.getPort());
  23.                        
  24.                         InputStream in = clntSock.getInputStream();
  25.                         OutputStream out = clntSock.getOutputStream();
  26.                        
  27.                         Scanner s = new Scanner(in);
  28.                         PrintWriter pw = new PrintWriter(out);
  29.                        
  30.                         String texto = s.nextLine();
  31.                         System.out.println(texto);
  32.                        
  33.                         if(texto == "GET /home.html HTTP/1.1"){
  34.                             System.out.println("oi");
  35.                         }
  36.                        
  37.                         pw.println("mensgem do servidor");
  38.                         pw.flush();
  39.                        
  40.                         clntSock.close();
  41.                 }
  42.                
  43.                 /* NOT REACHED */
  44.        
  45.         }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement