Advertisement
TrodelHD

Untitled

Apr 21st, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. import java.io.IOException;
  2. import java.io.ObjectInputStream;
  3. import java.io.ObjectOutputStream;
  4. import java.net.ServerSocket;
  5. import java.net.Socket;
  6. import java.util.ArrayList;
  7.  
  8. public class Main {
  9.  
  10. private static ServerSocket server;
  11. private Socket Con;
  12. private static ObjectOutputStream serveroutput;
  13. private static ObjectInputStream serverinput;
  14. private static Socket serverconnection;
  15. private ArrayList<Socket> cons;
  16.  
  17. public Main() throws IOException {
  18.  
  19. try {
  20. this.server = new ServerSocket(2021);
  21. System.out.println("server gestartet");
  22. waitforcon();
  23.  
  24. } catch (IOException e) {
  25. System.out.println("Server startup Error");
  26. e.printStackTrace();
  27. }
  28.  
  29.  
  30. }
  31.  
  32.  
  33. public void waitforcon() throws IOException {
  34.  
  35. while(true) {
  36.  
  37. try {
  38. this.Con = server.accept();
  39. serversetupStreams();
  40. System.out.println("client verbunden" + Con.getInetAddress());
  41. this.cons.add(Con);
  42. } catch (IOException e) {
  43. e.printStackTrace();
  44. }
  45.  
  46. }
  47.  
  48.  
  49. }
  50.  
  51. private void serversetupStreams() throws IOException{
  52. System.out.println("baue brΓΌcken");
  53. serveroutput = new ObjectOutputStream(Con.getOutputStream());
  54. serveroutput.flush();
  55. serverinput = new ObjectInputStream(Con.getInputStream());
  56.  
  57. }
  58.  
  59. private void waitforping() throws ClassNotFoundException, IOException {
  60.  
  61.  
  62. while(true) {
  63.  
  64. String[] cmd = (String[]) serverinput.readObject();
  65. verwerten(cmd);
  66. /*char[] cmd = s.toCharArray();
  67. int countpart = 0;
  68. for(int i = cmd.length; i > 0; i++) {
  69.  
  70. if(cmd[i] == '.') {
  71. countpart++;
  72. int vor = i;
  73.  
  74. for(int z = vor; z >0;z--) {
  75. char[] be1 = new char[z];
  76. be1[z] = cmd[z];
  77. }
  78. }
  79.  
  80. }*/
  81.  
  82. }
  83.  
  84. }
  85.  
  86. public void verwerten(String[] a) {
  87.  
  88.  
  89.  
  90. }
  91.  
  92. public static void main(String[] args) throws IOException {
  93. new Main();
  94. }
  95.  
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement