From 57224099202f8ecadea7945d9a3e019cb0e336f1 Mon Sep 17 00:00:00 2001 From: esoe Date: Mon, 10 Oct 2022 16:49:12 +0300 Subject: [PATCH] qq --- src/main/java/ru/molokoin/Connection.java | 41 +++++++++++++++++- src/main/java/ru/molokoin/ExchangeServer.java | 3 +- src/main/java/ru/molokoin/ServerLauncher.java | 3 +- target/classes/ru/molokoin/Connection.class | Bin 702 -> 2424 bytes .../classes/ru/molokoin/ExchangeServer.class | Bin 842 -> 910 bytes .../classes/ru/molokoin/ServerLauncher.class | Bin 1712 -> 1756 bytes 6 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/main/java/ru/molokoin/Connection.java b/src/main/java/ru/molokoin/Connection.java index c630449..d15232f 100644 --- a/src/main/java/ru/molokoin/Connection.java +++ b/src/main/java/ru/molokoin/Connection.java @@ -1,21 +1,58 @@ package ru.molokoin; +import java.io.IOException; +import java.io.RandomAccessFile; import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; import java.nio.channels.SocketChannel; +import java.nio.file.Path; +import java.nio.file.Paths; public class Connection { public SocketChannel accepted = null; public Connection(){} public Connection(SocketChannel accepted){ this.accepted = accepted; + this.put(); } //читаем из подключения - public void read(ByteBuffer byteBuffer){ + public void read(ByteBuffer byteBuffer) throws IOException{ // + accepted.read(byteBuffer); } //пишем в подключение - public void write(ByteBuffer byteBuffer){ + public void write(ByteBuffer byteBuffer) throws IOException{ // + accepted.write(byteBuffer); + } + //пишем страничку по умолчанию + public void put(){ + //accepted.write(null); + RandomAccessFile aFile; + try { + String stringPath = "src/main/webapp/upload.http"; + Path path = Paths.get(stringPath); + aFile = new RandomAccessFile(path.toAbsolutePath().toString(), "rw"); + FileChannel inChannel = aFile.getChannel(); + ByteBuffer buf = ByteBuffer.allocate(24); + int bytesRead; + bytesRead = inChannel.read(buf); + while (bytesRead != -1){ + System.out.println("Read " + bytesRead); + buf.flip(); + while(buf.hasRemaining()){ + //System.out.print((char) buf.get()); + accepted.write(buf); + } + buf.clear(); + bytesRead = inChannel.read(buf); + } + aFile.close(); + } + catch (IOException e) { + e.printStackTrace(); + } + } } diff --git a/src/main/java/ru/molokoin/ExchangeServer.java b/src/main/java/ru/molokoin/ExchangeServer.java index 65ee20c..84a6a55 100644 --- a/src/main/java/ru/molokoin/ExchangeServer.java +++ b/src/main/java/ru/molokoin/ExchangeServer.java @@ -1,7 +1,8 @@ package ru.molokoin; public class ExchangeServer { - public static Thread server = new Thread(new ServerLauncher()); + private static ServerLauncher launch = new ServerLauncher(); + public static Thread server = new Thread(launch); //Запуск сервера public void enable(ExchangeServer server){ diff --git a/src/main/java/ru/molokoin/ServerLauncher.java b/src/main/java/ru/molokoin/ServerLauncher.java index d9a550f..cd4d9f0 100644 --- a/src/main/java/ru/molokoin/ServerLauncher.java +++ b/src/main/java/ru/molokoin/ServerLauncher.java @@ -11,9 +11,10 @@ import java.util.Queue; * Подключения ставятся в очередь */ public class ServerLauncher implements Runnable{ - private int tcpPort = 0; + private int tcpPort = 8081; private ServerSocketChannel channel = null; private Queue connectionQueue = null; + private boolean isActive = false;//флаг проверки, запущен ли сервер @Override public void run() { diff --git a/target/classes/ru/molokoin/Connection.class b/target/classes/ru/molokoin/Connection.class index 33c8a5464c445d92e13588aa9291d5142a7524a6..a167da888fd7a1da3d48358fd04aec49fcd57da8 100644 GIT binary patch literal 2424 zcmah~TX)oC6y4uknrTRBY3a}wu#}6vL4$yR9Yotww9=a$WCRq=WYRV?O~y=yg7;h3 zk_Y_(KKaHoE*(JBAK<_74_Nn?xz>)WtE-uOm$T0~`|NY_*FV4g3E%=Y6+{G*eo&m<^9z+tbZegN9B) zPkZK?6-MuiTJy#AtmR)f zvW_LtIqR8*bHng$xvp%+f>pa9&@*sj0tZ3|4dhK0Z6{~>39v!p zOKhPdD$;mYvUrn7O<0u8m&R=k@8Nw82+GrP*?5O)+3iGUhG|?>@gcGbj4EH-7LG;9rbu_mCc8igfGwho&joLaXe68Ui@QrvVb z!j5S)cg&EBm z`N|+x(_Yaxt#W4V^$*9GR0sw*U!(lW5L1qKzQy^*k z_Jz>NvUvrXKw-c#@FWiKtcR8{u6o13CoAsMkzb&VmT)jr_o9YK-Mp7_?j!QSU6A=jD-$C&8MVULf9O0hcQX112A^Vh{yFrUr=H;@foHhDIh%Td zS7({V>*KMGo~O7n9`B9y#!GnXe9I$T`5AN1k-pja&J$$1TS~Z9!krR6kQZ{9M`)8A z$i=aYe6Ieu^|$>^ ppk<3eDGG!FUBRG&GYYOLm}X}Et;sDZRvyYnuN2NVG>YKce*w_iCBXmy delta 276 zcmew%w2zhR)W2Q(7#JAL8Kfq1{hln!s5*HSqt;|sHX}xs$rWt+oE!`+4D1Y?3>=d; zu*ui^GcW-m0|UR-b_Omj#;puITG~KjBT$Hmfe%Ou0hKcVl|wXf0mZl(_<4x|L67-~c!NEU7eBZDZ=T#y;!gv}6! OnSsLy37|L=gCqdI$QFSB diff --git a/target/classes/ru/molokoin/ExchangeServer.class b/target/classes/ru/molokoin/ExchangeServer.class index d71d0c39c48eab55444d079498fd0f4c461d09c5..74793444b8ccd752f264bb759a58f85203e79917 100644 GIT binary patch literal 910 zcmah{U2oGc6g^(kdJSRiR_MwYjPaQci98`5R`G)1sRD^kl_s9t)M`CaM{<*izr`j| ziAnqbeiY)`nP^iXc!(X}d(XM&9{cC7?>_*%!gG!dhCP!!kYo&J*KWNM@sQ+Bf# zCrYdAHA5xr4jH^R=~!~yT+>vh^%0;Epb4M&dk$X*bqG*JjpJ5HaM8<03vCP8W!Mc@ zqdl1G4DImKisV6Nl%9}aJJgc^PpuEtc_s|qizm#4#I*hb zVDJZNZesaP*@0T+&M)ls;E+71(976>Z_T8?x;2FMDy?;jGTfk3&s71PD+H$tY+Yje z3a!%%Y%g&85}mJ(V~Xh(~`^6eI8pbiU#7QcE#=lYHD+ P8HD2*LN`d)$v^rH(3h#T delta 443 zcmaiwy-EX75QV?1?%#FQO`fdZ*QrB3kH0E zRKAZO&b^CKVqtNIJ2U5;IWu=&&(*!p*Ee97%}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