Guest User

Untitled

a guest
Jul 29th, 2016
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. java.io.EOFException
  2. at java.io.DataInputStream.readFully(Unknown Source)
  3. at java.io.DataInputStream.readLong(Unknown Source)
  4. at server.connect(Server_v0.java:104)
  5. at server.<init>(Server_v0.java:78)
  6. at server.main(Server_v0.java:62)
  7.  
  8. java.net.BindException: Address already in use: JVM_Bind
  9. at java.net.DualStackPlainSocketImpl.bind0(Native Method)
  10. at java.net.DualStackPlainSocketImpl.socketBind(Unknown Source)
  11. at java.net.AbstractPlainSocketImpl.bind(Unknown Source)
  12. at java.net.PlainSocketImpl.bind(Unknown Source)
  13. at java.net.ServerSocket.bind(Unknown Source)
  14. at java.net.ServerSocket.<init>(Unknown Source)
  15. at java.net.ServerSocket.<init>(Unknown Source)
  16.  
  17. public static void main(String[] arg) throws ClassNotFoundException, SQLException{
  18.  
  19. new Server_v0();
  20.  
  21. }
  22.  
  23. Server_v0(){
  24.  
  25. JFrame f = new JFrame("Server");
  26. f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  27. f.setSize(200, 250);
  28. f.setLayout(new BorderLayout());
  29.  
  30. area = new JTextArea();
  31. f.add(area);
  32.  
  33. f.setAlwaysOnTop(true);
  34. f.setVisible(true);
  35. connect();
  36.  
  37. }
  38.  
  39. public void connect(){
  40.  
  41. int port = 60000;
  42. int connection = 1000;
  43.  
  44. try {
  45. @SuppressWarnings("resource")
  46. ServerSocket ss = new ServerSocket(port, connection);
  47. area.append("Wait connect...");
  48.  
  49. while(true){
  50. Socket socket = ss.accept();
  51.  
  52. InputStream in = socket.getInputStream();
  53. DataInputStream din = new DataInputStream(in);
  54.  
  55. int filesCount = din.readInt();//получаем количество файлов
  56. area.setText("Передается " + filesCount + " файловn");
  57.  
  58. for(int i = 0; i<filesCount; i++){
  59. area.append("Принят " + (i+1) + " файл: n");
  60.  
  61. long fileSize = din.readLong(); // получаем размер файла
  62.  
  63. fileName = din.readUTF(); //приём имени файла
  64.  
  65.  
  66.  
  67. area.append("Имя файла: " + fileName+"n");
  68. area.append("Размер файла: " + fileSize + " байтn");
  69.  
  70. byte[] buffer = new byte[64*1024];
  71. FileOutputStream outF = new FileOutputStream("D://Photo_and_Video//" + fileName);
  72.  
  73. int count, total = 0;
  74.  
  75. while ((count = din.read(buffer, 0, (int) Math.min(buffer.length, fileSize-total))) != -1){
  76. total += count;
  77. outF.write(buffer, 0, count);
  78.  
  79. if(total == fileSize){
  80. break;
  81. }
  82.  
  83. }
  84.  
  85. outF.flush();
  86. outF.close();
  87.  
  88. area.append("Файл принятn---------------------------------n");
  89.  
  90.  
  91. }
  92. }
  93. }
  94. catch(Exception e){
  95. e.printStackTrace();
  96. new Server_v0();
  97. }
  98. }
Add Comment
Please, Sign In to add comment