Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package serveris;
- import java.net.ServerSocket;
- import java.net.Socket;
- import java.util.ArrayList;
- /**
- *
- * @author Justas
- */
- public class Serveris {
- public static void main(String[] a){
- ServerSocket serverSocket = null;
- //sarasas kuriame saugoma info apie vartotojus
- ArrayList<User> klientai = new ArrayList();
- int counter = 1;
- try{
- //sukuriam serversocket objekta
- serverSocket = new ServerSocket(1234);
- boolean testi = true;
- while(testi){
- Socket clientSocket = serverSocket.accept();
- System.out.println("sulauke naujo kliento" + clientSocket.getInetAddress().getHostAddress());
- String nikas = "Klientas_"+counter++;
- User klientas = new User(clientSocket,klientai,nikas);
- klientas.out.println("nick"+nikas);
- for(User u : klientai){
- u.out.println("in"+ nikas);
- klientas.out.println("in"+u.nick);
- }
- klientai.add(klientas);
- klientas.start();
- }
- } catch (Exception e){
- try{
- serverSocket.close();
- }catch (Exception ex){
- }
- System.exit(1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement