Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
1
Language: Java
Posted by: Zeeshan Ali
Added: Jan 9, 2021 10:41 PM
Views: 6
Tags: no tags
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package chat;
  7.  
  8. import java.io.BufferedReader;
  9. import java.io.InputStreamReader;
  10. import java.io.PrintWriter;
  11. import java.net.ServerSocket;
  12. import java.net.Socket;
  13. import javax.swing.JOptionPane;
  14.  
  15. /**
  16.  *
  17.  * @author Zeeshan
  18.  */
  19. public class server {
  20.    
  21.     ServerSocket ss;
  22.     Socket s;
  23.     PrintWriter pw;
  24.     public server(){
  25.         try {
  26.                ss = new ServerSocket(constants.PORT);
  27.                System.out.println("Listening for Clients");
  28.                s = ss.accept();
  29.               /// if(s.isConnected()){
  30.                    System.out.println("Client Connected");
  31.                    in = new InputStreamReader(s.getInputStream());
  32.                    BufferedReader bf = new BufferedReader(in);
  33.                    String message_from_client = bf.readLine();
  34.                    System.out.println("Client : "+message_from_client);
  35.              //  }
  36.         } catch (Exception e) {
  37.             JOptionPane.showMessageDialog(null,e.getMessage(),"E38 server",1);
  38.         }
  39.        
  40.     }
  41. }
  42.