|
|
|
@ -13,20 +13,20 @@ public class Connection {
@@ -13,20 +13,20 @@ public class Connection {
|
|
|
|
|
public Connection(){} |
|
|
|
|
public Connection(SocketChannel accepted){ |
|
|
|
|
this.accepted = accepted; |
|
|
|
|
this.write(); |
|
|
|
|
this.read(); |
|
|
|
|
write(); |
|
|
|
|
read(); |
|
|
|
|
} |
|
|
|
|
//читаем из подключения
|
|
|
|
|
public void read(){ |
|
|
|
|
try{ |
|
|
|
|
RandomAccessFile aFile; |
|
|
|
|
//RandomAccessFile aFile;
|
|
|
|
|
ByteBuffer buf = ByteBuffer.allocate(1024); |
|
|
|
|
int bytesRead = accepted.read(buf); |
|
|
|
|
while (bytesRead != -1){ |
|
|
|
|
System.out.println("Read " + bytesRead); |
|
|
|
|
buf.flip(); |
|
|
|
|
while(buf.hasRemaining()){ |
|
|
|
|
System.out.print((char) buf.get()); |
|
|
|
|
System.out.print((char)buf.get()); |
|
|
|
|
//accepted.write(buf);
|
|
|
|
|
} |
|
|
|
|
buf.clear(); |
|
|
|
@ -37,7 +37,7 @@ public class Connection {
@@ -37,7 +37,7 @@ public class Connection {
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//пишем в подключение
|
|
|
|
|
//пишем в подключение из файла
|
|
|
|
|
public void write(){ |
|
|
|
|
//accepted.write(null);
|
|
|
|
|
RandomAccessFile aFile; |
|
|
|
@ -53,7 +53,8 @@ public class Connection {
@@ -53,7 +53,8 @@ public class Connection {
|
|
|
|
|
System.out.println("Write " + bytesRead); |
|
|
|
|
buf.flip(); |
|
|
|
|
while(buf.hasRemaining()){ |
|
|
|
|
//System.out.print((char) buf.get());
|
|
|
|
|
//char c = (char) buf.get();
|
|
|
|
|
//System.out.print(c);
|
|
|
|
|
accepted.write(buf); |
|
|
|
|
} |
|
|
|
|
buf.clear(); |
|
|
|
|