Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.net.*; // for Socket, ServerSocket, and InetAddress
- import java.io.*; // for IOException and Input/OutputStream
- import java.util.Scanner;
- public class TCPEchoServer {
- private static final int BUFSIZE = 32; // Size of receive buffer
- public static void main (String[] args) throws IOException {
- int servPort = 8000;
- // Create a server socket to accept client connection requests
- ServerSocket servSock = new ServerSocket(servPort);
- for (;;) { // Run forever, accpeting and servicing connections
- Socket clntSock = servSock.accept(); // Get client connection
- System.out.println ("Handling client at " +
- clntSock.getInetAddress().getHostAddress() + " on port " +
- clntSock.getPort());
- InputStream in = clntSock.getInputStream();
- OutputStream out = clntSock.getOutputStream();
- Scanner s = new Scanner(in);
- PrintWriter pw = new PrintWriter(out);
- String texto = s.nextLine();
- System.out.println(texto);
- if(texto == "GET /home.html HTTP/1.1"){
- System.out.println("oi");
- }
- pw.println("mensgem do servidor");
- pw.flush();
- clntSock.close();
- }
- /* NOT REACHED */
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement