Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.net.*;
- import java.util.ArrayList;
- import java.util.Scanner;
- import java.io.*;
- public class MainServer {
- //GAME SERVER
- public static ArrayList<Socket> connectionArray = new ArrayList<Socket>();
- public static ArrayList<String> usersArray = new ArrayList<String>();
- public static void main(String args[]) throws IOException{
- try{
- final int PORT = 666;
- ServerSocket SERVER = new ServerSocket(PORT);
- System.out.println("WAITING...");
- while(true){
- Socket userSocket = SERVER.accept();
- connectionArray.add(userSocket);
- System.out.println("USER: " + userSocket.getLocalAddress().getHostAddress() + " CONNECTED");
- addUser(userSocket);
- //add a client accept thing here once the game client is made -ben
- }
- }catch(Exception ex){
- ex.printStackTrace();
- }
- }
- public static void addUser(Socket X) throws IOException{
- Scanner INPUT = new Scanner(X.getInputStream());
- String userName = INPUT.nextLine();
- usersArray.add(userName);
- for(int i = 1; i <= MainServer.connectionArray.size(); i ++){
- Socket TEMP = MainServer.connectionArray.get(i-1);
- PrintWriter OUT = new PrintWriter(TEMP.getOutputStream());
- OUT.println("$:/" + usersArray);
- OUT.flush();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement