From 8bf8b18d5097335fec7fdee5a57896fe3dbab302 Mon Sep 17 00:00:00 2001 From: esoe Date: Mon, 10 Oct 2022 23:50:15 +0300 Subject: [PATCH] qq --- src/main/java/ru/molokoin/Connection.java | 38 +++++++++++------- src/main/java/ru/molokoin/ExchangeServer.java | 5 ++- .../java/ru/molokoin/MainFrameController.java | 18 ++++++--- target/classes/ru/molokoin/Connection.class | Bin 2424 -> 2542 bytes .../classes/ru/molokoin/ExchangeServer.class | Bin 1185 -> 1174 bytes .../ru/molokoin/MainFrameController.class | Bin 1723 -> 2084 bytes 6 files changed, 40 insertions(+), 21 deletions(-) diff --git a/src/main/java/ru/molokoin/Connection.java b/src/main/java/ru/molokoin/Connection.java index d15232f..118031b 100644 --- a/src/main/java/ru/molokoin/Connection.java +++ b/src/main/java/ru/molokoin/Connection.java @@ -13,20 +13,32 @@ public class Connection { public Connection(){} public Connection(SocketChannel accepted){ this.accepted = accepted; - this.put(); + this.write(); + this.read(); } //читаем из подключения - public void read(ByteBuffer byteBuffer) throws IOException{ - // - accepted.read(byteBuffer); + public void read(){ + try{ + 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()); + //accepted.write(buf); + } + buf.clear(); + bytesRead = accepted.read(buf); + } + } + catch (IOException e) { + e.printStackTrace(); + } } //пишем в подключение - public void write(ByteBuffer byteBuffer) throws IOException{ - // - accepted.write(byteBuffer); - } - //пишем страничку по умолчанию - public void put(){ + public void write(){ //accepted.write(null); RandomAccessFile aFile; try { @@ -34,11 +46,11 @@ public class Connection { Path path = Paths.get(stringPath); aFile = new RandomAccessFile(path.toAbsolutePath().toString(), "rw"); FileChannel inChannel = aFile.getChannel(); - ByteBuffer buf = ByteBuffer.allocate(24); + ByteBuffer buf = ByteBuffer.allocate(1024); int bytesRead; bytesRead = inChannel.read(buf); while (bytesRead != -1){ - System.out.println("Read " + bytesRead); + System.out.println("Write " + bytesRead); buf.flip(); while(buf.hasRemaining()){ //System.out.print((char) buf.get()); @@ -52,7 +64,5 @@ public class Connection { catch (IOException e) { e.printStackTrace(); } - } - } diff --git a/src/main/java/ru/molokoin/ExchangeServer.java b/src/main/java/ru/molokoin/ExchangeServer.java index f4aa73a..fb9df17 100644 --- a/src/main/java/ru/molokoin/ExchangeServer.java +++ b/src/main/java/ru/molokoin/ExchangeServer.java @@ -4,8 +4,9 @@ import java.util.Queue; import java.util.concurrent.ArrayBlockingQueue; public class ExchangeServer { - private static ServerLauncher launch; + static ServerLauncher launch; public static Thread server; + static Queue connectionQueue; //Запуск сервера public void enable(ExchangeServer server){ @@ -16,7 +17,7 @@ public class ExchangeServer { // } public static void main(String[] args) { - Queue connectionQueue = (Queue) new ArrayBlockingQueue(1024); + connectionQueue = (Queue) new ArrayBlockingQueue(1024); launch = new ServerLauncher(8081, connectionQueue); server = new Thread(launch); server.setName("ServerLauncherThread"); diff --git a/src/main/java/ru/molokoin/MainFrameController.java b/src/main/java/ru/molokoin/MainFrameController.java index 77a8d7a..1ea9400 100644 --- a/src/main/java/ru/molokoin/MainFrameController.java +++ b/src/main/java/ru/molokoin/MainFrameController.java @@ -1,27 +1,29 @@ package ru.molokoin; import java.net.URL; +import java.util.Queue; import java.util.ResourceBundle; +import java.util.concurrent.ArrayBlockingQueue; import javafx.event.Event; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.scene.control.Button; import javafx.scene.control.TextField; -import ru.molokoin.example.ExchangeServer; +import ru.molokoin.ExchangeServer; public class MainFrameController implements Initializable{ @FXML public Button btn; @FXML public TextField portField; - public ExchangeServer server; + public ExchangeServer es; @Override public void initialize(URL location, ResourceBundle resources) { System.out.println("Инициализация компонентов интерфейса ..."); try { - server = new ExchangeServer(); + es = new ExchangeServer(); } catch (Exception ex) { System.out.println(ex); } @@ -31,13 +33,19 @@ public class MainFrameController implements Initializable{ public void buttonClicked(Event e){ if (btn.getText().equals("START")){ btn.setText("STOP"); - server.start(); + es = new ExchangeServer(); + // + es.connectionQueue = (Queue) new ArrayBlockingQueue(1024); + es.launch = new ServerLauncher(8081, es.connectionQueue); + es.server = new Thread(es.launch); + es.server.setName("ServerLauncherThread"); + es.server.start(); }else { btn.setText("START"); try { - server.finish(); + //server.finish(); } catch (Exception ex) { System.out.println(ex); } diff --git a/target/classes/ru/molokoin/Connection.class b/target/classes/ru/molokoin/Connection.class index 85c95e1fff46aa449b002a56dd8c9a7851a312fc..2a488a49c1e67eb484013eb878de99268dda903f 100644 GIT binary patch delta 1383 zcmY+DT~ixX7{~u-ce9)9th}WO;UyBF3WS${w6q0EOTo6rS9E{>s0ev=IploeBrkqbWIEmMo-g9G@ts`xd%J-Cm(-;$Q z=G>)Zdcn=+vbkB$@1jzlac~yH^qZMayLlT)oVPF`5R{E(Fy`P5g{<5QI#F@r?6~*=PP|=-5`uig8&qj1qpXEVSq1|R0x0LM0#&F)n6jLj@OBt}t>lRT z;iHG(!+S^>07N;x4eF*V4LnB8So~2DPDcq1L+cp+9($i6K2_DRiLPh~Jtgcf;SjY$ zsdbc5%k8nRN;uB-^>4QR;xe9!KiUZp)xO>OWgY(0?IoPsU_M|HQyj4FRX^m_SWT7@ zR#<}|`)NZRie0Ej526_4IznnE(TH<2m_#$(_u?Xdhf8Sj+~eED@3d&)46RaZy8_2? zfz~>$4Zd$O{aY-c3Fa0v85YkLYFSg%-m}H6P+usLMvg}-({U=O6 zhCBWgnW@evm=kz{952t}Cf-$D7W$2CjQzeEqsCXltv+)dqyJ%ij~GMdE=OgcK)#@e zsl)pzC5wur+Ki`mgM>`7e8vn#@*E@P9iFSWzsoa;J*=~nEqC!gBnYjWkb1c5#X;=D z0QS?ik5~>6$04M-F7WFTLEoYNLkwXRM^L=afBgZ5@dfFtYm_7m0@z{Ph&h^mL`XX2 z$M}S_9o(ktr~J}_X?(__45m$av+yzbxHk)vQMYHId9&zLvlxKo!OvKjwve^3(zrdB UhCq0WfjN?$xo~~JIy8L#FO;VA9RL6T delta 1282 zcmah|OK%%h6#njvXYOP=(A35zP6}}zC64XJA?YKyO=(SCD0vX z==Y%h!isCP%L@<%p)^AfDuS zLTs{OIf8x)?aNT)@}_HL*UM$gVF=G&Hm{m#yIN0Y_uMBKlntlqS{}l%fkE_ZcuM>t z$EM>9-F`;Rv@7X?>s0NEjs#L1NruoKSh-rW(hH`$+B9$&V+?Y|az!?9`qVf>j~_;q zdDC90ubnBCtY-5ZW$eQQj&Mve1Rq8+a1_VH4}p|6fhhyeAR}7RU{J$J2Fcmbk;W+l z9M1}-q_i~77|7x|aa5U9b9kQPoET?4@(VaGW>{RE@uZm*wi1hVVIB({Fa5i<&8BOu z8F(3a@iU9D3*rxUFhoKtc~U*5qkz{uwndSYdbI*xH*gVeh&d^dDPT&+TUh2W|B-}x zT_CAk63j9QwS+|m-tb&CTSpF-fif!MCu!(n4pjq}afQKHHJf>B&8*s_GD#R8UGicn z-v-%Asb-mu*LTCf+t7SZy-Bwg1J0!4JxaBIJR_QTPQ17uMm6sTadB6ytQ zd&n0cD~c{UW$(l5iLYTK+vqDkK-GQXFvUgi09oHd))B*ik39G{a_c{#haQ6NCFs8Y zfeu3>3M!RtQQ4drJ_{b2OUd71KC2gyl<_z zhY?n#Tb*wSzrGD^F4cy!L*)Tm_yo}wWdAzyc#K>FWDUZ=5S@lGf{zgK@k||39F|wuMQ8Jc66_wm!v_uTq}0p#JY)zyK;($5o=2@gX*F z4GoFtHfg;>t`S@!uM{auj`;nE)(B95pxJReb#gpdCMiL&a^ diff --git a/target/classes/ru/molokoin/ExchangeServer.class b/target/classes/ru/molokoin/ExchangeServer.class index fc5c91e6a6e45cab7f77d8e86a09f09b976dfbeb..a200d714c3538732a684eead75ef46650bfd5a69 100644 GIT binary patch literal 1174 zcmah|>rN9v6#j;mZd+HOg@SUCix;+_tfDAbAW@?rFDm$wBmM6S$haqK^ z>kR4L;F#x;LczpM+@ktbPw@Syb;RX?bL10#u^PCJUw5RZ?pp3tin8+b-;NF1BNulys!~>Q3kfCJl4RTDKC@jmwFfs;~ z6E7kbGmkPJDTK!ilUCm>A0we@>0;O>3}mx-$}pbnp@;L##B;0@OKl$RJ1tVB)Q@=0 zj;i_6#D-FGxE(r@-eua64U%f?FLW~GYe6Jk{?1cMk0o_kRV-tH#!S(lkwR9@N~fIa zm-ejUk-RtPJOmSII@24Xb%ZQ7?Tq%}yRR?8Ewp9jLv2pfN_-QMv`NaR+YR? z-;lBmCf?GC6S1?Ks8S7rQ1x#AAENkAh#c-|QVUA%kGJ@20T^~3mS4E%ohbqC-r-sq45cIXN_aQ2JZ zcI&kD`JF(bQf&w%Kb#$TCKBkgV89GDaUq7oOEH(t!&cNNb1EOJ4IN{w671Nfi2}ye z*UQkB1!K}e4>TQ9;d_})l~7h+GvS^rI#mlgQYp*|WOhCOtLN9;FQ)ij_)+Y)iM}i{W3c&Adgi>>JZ#Vb-^n#V3tF?&KWis QsUvlnO(KCUauTl}0TlvDQUCw| diff --git a/target/classes/ru/molokoin/MainFrameController.class b/target/classes/ru/molokoin/MainFrameController.class index 087e32406fd70f4c19cbac2d1cfca934d34b2730..7137ec4dc2e581f683faca68e9e3038f0f21c6e3 100644 GIT binary patch delta 705 zcmZXRO>YuW6o#LRP;eZ>hpjZVsfik)7{!&*kS2b_MI)G&7IbVy2RZ^}n9*SdXH_^nEU?GvjAK=R0;NLJY-VTdm-Q0W6z305od(Iu7{t#1s{Q34BSmE`a@+%QA zI)cT#<7L~nX}9dAHBiJmp)O3{3<3wD7iL|M+SR*y)^nR?wq{#3&v6XP&E9bw{mos| zuCPNd9}#vn;)88o3Fqq0(em!aBZFL1HR*qLqta3TFRpLZSb>*?%xVk;`2mU;0)(Tvd9uk`=3JP-cN!AF=SpfpC);^+7Jltyd~sEnyt(K!; kGPTYP=48>?iCMWPWh8CW!9{RWo@WUBrV^2nC!+w}zfAnJmjD0& delta 340 zcmZ1?u$!0b)W2Q(7#J9A8KNd~J(6Q9PAw`+En;L)@hK|R&&|)t&(6=x(@(8P%q_@C z-S}@Rqlgj~iOutwwlb=6F=#LZ@-PH32rx3R7MCOzm4HM-co;%KB5Y}yd6~r-lW(xD zX5^jR!WJhe#=yZK!63{a$so=k#URHZGx;-HSp6mjCI)7pi|n+vFj#M6uoZIN#^5@W zK@7wd^4`Ya3uI_-V+dHzAO{u#N<)Q$mosqtZeozq*~Xx|k%5sxo56^|l)(UKnh4N5 zH3m)~sldR`pa`^8i9w!06-cT9RcQd#X)>5GXaPe(&yGP9tPJb~1~H)1K){Y6j3FFo gq!|M{5Ss&?XaN-EU|?1XVrMX52g*bM`AiIv0B7<=e*gdg