From 869775ed59590a757707126f0cdd5aa50b00f50c Mon Sep 17 00:00:00 2001 From: esoe Date: Tue, 11 Oct 2022 13:15:42 +0300 Subject: [PATCH] qq --- src/main/java/ru/molokoin/Connection.java | 13 +++++++------ src/main/java/ru/molokoin/ServerLauncher.java | 10 +++++----- target/classes/ru/molokoin/Connection.class | Bin 2542 -> 2534 bytes .../classes/ru/molokoin/ServerLauncher.class | Bin 1926 -> 1916 bytes 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/main/java/ru/molokoin/Connection.java b/src/main/java/ru/molokoin/Connection.java index 118031b..012856a 100644 --- a/src/main/java/ru/molokoin/Connection.java +++ b/src/main/java/ru/molokoin/Connection.java @@ -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 { e.printStackTrace(); } } - //пишем в подключение + //пишем в подключение из файла public void write(){ //accepted.write(null); RandomAccessFile aFile; @@ -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(); diff --git a/src/main/java/ru/molokoin/ServerLauncher.java b/src/main/java/ru/molokoin/ServerLauncher.java index b894bb8..bb59452 100644 --- a/src/main/java/ru/molokoin/ServerLauncher.java +++ b/src/main/java/ru/molokoin/ServerLauncher.java @@ -11,28 +11,28 @@ import java.util.Queue; * Подключения ставятся в очередь */ public class ServerLauncher implements Runnable{ - private int tcpPort = 8081; + private int port = 8081; private ServerSocketChannel channel = null; private Queue connectionQueue = null; private boolean isActive = false;//флаг проверки, запущен ли сервер ServerLauncher(int port, Queue connectionQueue){ - tcpPort = port; + this.port = port; this.connectionQueue = connectionQueue; } @Override public void run() { try{ - this.channel = ServerSocketChannel.open(); - this.channel.bind(new InetSocketAddress(tcpPort)); + channel = ServerSocketChannel.open(); + channel.bind(new InetSocketAddress(port)); } catch(IOException e){ e.printStackTrace(); return; } while(true){ try{ - SocketChannel accepted = this.channel.accept(); + SocketChannel accepted = channel.accept(); System.out.println("Socket accepted: " + accepted); //todo check if the queue can even accept more sockets. this.connectionQueue.add(new Connection(accepted)); diff --git a/target/classes/ru/molokoin/Connection.class b/target/classes/ru/molokoin/Connection.class index 8da01823e3e87ef00876caff89c0a0146faaeb59..5e4ed3e467aeb33478e5b3dc69a547634a254a7c 100644 GIT binary patch delta 186 zcmX|)F$)1<0EVAKj*@VbOIcWuQY6A586@jDr%XnZ#b7ch27}AO53ox5DF4T(3`X%y zrsu7v-sh=3v{PNRRXn(XQP{(cXg75skQT(NM;d1mcT!d)b0r%SQ)EJgDOKj= TSzxfF&WZ+Wnrvt}mVfsHua+w) delta 194 zcmaDR{7!g-1A8<-0}Bu`FvJV8FzjHE^wrwJz@xK`LEdgTgX1O!mE8lm#-KCT(MI1JYiz{(l5ge&KKfWGByNuh3y)5MXd)h+v3h zU}lH{+7!hQ&A`YI1GG_zf$cwoFarxakk8H_#mK-g*_`96swG1zgE>PkgEd1jgAGFs eg9$?ugB?Q~gFQnhg9AesgCj#9gY)D-&Zz*%I4eW| diff --git a/target/classes/ru/molokoin/ServerLauncher.class b/target/classes/ru/molokoin/ServerLauncher.class index 2449016998cfa0182e41e6f7f43fcb77adda188e..8ab02418cb13261150bb9599e8b8f61cfe0bad12 100644 GIT binary patch delta 608 zcmYk2O-~b17=@oZojRpVK>Pr0K$=LUP_$N|C>0ecD$+`^NT~`qmJtisHg#%b<<5n! z$oz;dT%ppcB*vw2oZQM)}UW6 zXk-QLn?KvVUgo*)R6el3s(oFHJk(f{-)wYOto(X-reao19fL>j54h*WOAQY~u0B9B zIto2<*8eLlQjyE2L!L*Z^9xlfu-N~RQ``9ZKj7P8AS>@h8BjiH|O#oFvU0QQNI0 k2Xib-kPtyk9?K~sarU$o3Dt~iK_lue%R`z^q@<{9 delta 585 zcmYk3Pfrs;7{;I3-MUaFMU)h6z(29or4?%xtca+H6)UY2i!D_^*Sg|DZP&UrdeV~@ zPtAM+Pd($Gt=fdM;b8m##+zq9fCPNI#Kg<{&ig!>XMQuY>3iMn-ProF4qzOsb#KO_ z+C?j~w(y2|6suCT#V>ZaQ$twAAVaABB;?_U;J6r-M%W2akq+)3!by%E#26GUIhgZ8 z!)cCTjEIJm9*<*G#aV{EEBZ4%YF47jnZ)y=VcBM-%yABV4Bb}MEZbRIFRsp2^`g;E zIM0daf{4kn1D9}F#RS7{H=(4Lm!sJiPi^Bd$0V+ZSMnitRlJq^*)_2)`#Tc2-o}|0 zKjZ)nX^tD15nJ*Y4YM3Kkrfk4Fm?-h6}kVoGCL4eL#N<*Of#r1SE;PxHiN(Z)9>@5 zfQ5GYB12HCTfO3&(lc-ux{7;r4;Qdzo2BS%&8Qh1_fdSmsm!yNL3Du88;8&Z4v9Lb z|5JRVFdRi6)n0ObLm>rN3V*_}j|hZ6Ake~4f%?8Cq7F{w8|X|$9GqEedk)4@?{Kk& zL}AZV6G<{s4l)kr$n9^TpcNub-1&?p3HiqMcXwxF`>T6M00W5Q2(ri_F8=IF4?loG gAQAe7hghano^W=wM+DUcc~M2&Q>8+tNs@$>zx6kPrT_o{