Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package y04;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.OutputStreamWriter;
- import java.io.PrintWriter;
- import java.net.ServerSocket;
- import java.net.Socket;
- import java.util.ArrayList;
- public class Communications {
- private static final int PORT = 8888;
- private BufferedReader netIn;
- private PrintWriter netOut;
- private ServerSocket socket;
- private Socket sock;
- private Commands command;
- private ArrayList<String> list = new ArrayList<String>();
- private Commands Command;
- public Communications() throws IOException{
- try{
- socket = new ServerSocket(PORT);
- System.out.println("Server startis...");
- } catch(IOException e){
- System.out.println("Error starting server: " +e.getMessage());
- }
- conListen();
- }
- public Socket getSock() {
- return sock;
- }
- public void conListen(){
- try{
- sock = socket.accept();
- try{
- netIn = new BufferedReader(new InputStreamReader(sock
- .getInputStream()));
- netOut = new PrintWriter(new BufferedWriter(
- new OutputStreamWriter(sock.getOutputStream())), true);
- System.out.println("Saabus mängija");
- while(true){
- String Client = netIn.readLine();
- if (Client != null) {
- command(Client);
- } else if (Client == null) {
- conListen();
- }
- }
- }finally{
- sock.close();
- }
- }catch(IOException e){
- e.printStackTrace();
- }
- }
- public void command(String cmd){
- String s[] = cmd.split(" ");
- if(s != null){
- for(int i=0;i<s.length;i++){
- new Commands(s[i]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement