From f01ce3dff0926f5dc3ee9af38eada90de5a63c4c Mon Sep 17 00:00:00 2001 From: Abbas Aliakbari Date: Fri, 10 Aug 2018 23:31:41 +0430 Subject: [PATCH] Implement base class and test program for server in java with event Implement base class and test program for server in java with event that clients in anothers language connect to its. --- build.xml | 73 + build/built-jar.properties | 4 + build/classes/javaside/JavaSide$1.class | Bin 0 -> 1523 bytes build/classes/javaside/JavaSide$2.class | Bin 0 -> 2279 bytes build/classes/javaside/JavaSide.class | Bin 0 -> 1525 bytes .../classes/javaside/Socket/TcpClient$1.class | Bin 0 -> 1556 bytes build/classes/javaside/Socket/TcpClient.class | Bin 0 -> 4114 bytes .../Socket/TcpClientEventHandler.class | Bin 0 -> 224 bytes .../javaside/Socket/TcpServer$1$1.class | Bin 0 -> 1175 bytes .../classes/javaside/Socket/TcpServer$1.class | Bin 0 -> 1633 bytes build/classes/javaside/Socket/TcpServer.class | Bin 0 -> 2745 bytes .../Socket/TcpServerEventHandler.class | Bin 0 -> 228 bytes dist/JavaSide.jar | Bin 0 -> 19057 bytes dist/README.TXT | 32 + manifest.mf | 3 + nbproject/build-impl.xml | 1420 +++++++++++++++++ nbproject/genfiles.properties | 8 + nbproject/private/private.properties | 2 + nbproject/private/private.xml | 12 + nbproject/project.properties | 74 + nbproject/project.xml | 15 + src/javaside/JavaSide.java | 82 + src/javaside/Socket/TcpClient.java | 136 ++ .../Socket/TcpClientEventHandler.java | 7 + src/javaside/Socket/TcpServer.java | 85 + .../Socket/TcpServerEventHandler.java | 7 + 26 files changed, 1960 insertions(+) create mode 100644 build.xml create mode 100644 build/built-jar.properties create mode 100644 build/classes/javaside/JavaSide$1.class create mode 100644 build/classes/javaside/JavaSide$2.class create mode 100644 build/classes/javaside/JavaSide.class create mode 100644 build/classes/javaside/Socket/TcpClient$1.class create mode 100644 build/classes/javaside/Socket/TcpClient.class create mode 100644 build/classes/javaside/Socket/TcpClientEventHandler.class create mode 100644 build/classes/javaside/Socket/TcpServer$1$1.class create mode 100644 build/classes/javaside/Socket/TcpServer$1.class create mode 100644 build/classes/javaside/Socket/TcpServer.class create mode 100644 build/classes/javaside/Socket/TcpServerEventHandler.class create mode 100644 dist/JavaSide.jar create mode 100644 dist/README.TXT create mode 100644 manifest.mf create mode 100644 nbproject/build-impl.xml create mode 100644 nbproject/genfiles.properties create mode 100644 nbproject/private/private.properties create mode 100644 nbproject/private/private.xml create mode 100644 nbproject/project.properties create mode 100644 nbproject/project.xml create mode 100644 src/javaside/JavaSide.java create mode 100644 src/javaside/Socket/TcpClient.java create mode 100644 src/javaside/Socket/TcpClientEventHandler.java create mode 100644 src/javaside/Socket/TcpServer.java create mode 100644 src/javaside/Socket/TcpServerEventHandler.java diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..061b9c4 --- /dev/null +++ b/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project JavaSide. + + + diff --git a/build/built-jar.properties b/build/built-jar.properties new file mode 100644 index 0000000..13680d0 --- /dev/null +++ b/build/built-jar.properties @@ -0,0 +1,4 @@ +#Fri, 10 Aug 2018 22:26:22 +0430 + + +D\:\\Projects\\Temp\\SocketInVBAndJava\\JavaSide= diff --git a/build/classes/javaside/JavaSide$1.class b/build/classes/javaside/JavaSide$1.class new file mode 100644 index 0000000000000000000000000000000000000000..76b04de4b991745d66a823e972d332fc9e2574a6 GIT binary patch literal 1523 zcmaJ>Yje{^6g_L3$W{e$T#^(*8$%LsOo9oI&^Bq>U;-E%pg0Zf^aI_nSGPTnuTvId}m=@VDv!xvwBbJ*RhHY zR3tFfd?OEJ?6p;`6}rDFUE6Xyt>oj1z{si>czR9Xi^@m*=C=iM^{}l7(DVZJth>LX zqAj`ObEnh{UFmPj$TRD~W=`*Uv4GPE0u|ML8OMst@gc?&l4_CE>=IcN!eCRyvD{_2 ziAp2!s`)b5t+jOI1-mPTK*9Ar73kMqTR=2O$R`s6Z}L0hEszg`b=OrLO}9$JoVLQC z?uRiC*sZV|x$2>3$e%sral=GmdK-aD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gA_rF(2u7|2ou&Oc#A$tQPGcWT;Vb;ttzbX5Iq(4kKi177X0M z=UX7GBfn#{E_Vt!gqVk9ao>5^w@g1DjMOA}w=8xyZ$NJDRfj<&n(Ey;W_ zx*6CoVqRFG=ab2MstrlUcPwnt^Oou)+F#9uO%8~A?TT*15A89Ism~hruHm_#(3J>> zAE6ysL+0L-`^voQ-jkmrctuR3gHF`9lMWTUA?)FJo-i+P?;^t-!ApF#bGU@Fe6EX; z_5@$+Nt8KPVVpt>_p{W?@{|q?<2YVsAU!yPSGbd+b{c)?kHVcv!X2QcLH&O)Iih1Q zV<^%l;h(3CN}xV)Xbs&njqDlG@;KpLj$HS|YLRQ|^WDg^I&25LMk$4pc%9!gA)dxj d&N{iak6)k-ckwO0X4NiJQkA$uFa=Ct@;|O5N?ZT{ literal 0 HcmV?d00001 diff --git a/build/classes/javaside/JavaSide.class b/build/classes/javaside/JavaSide.class new file mode 100644 index 0000000000000000000000000000000000000000..7d95468daa97c77a3480fc5bdbfc87c0b8bbc08e GIT binary patch literal 1525 zcmaJ>?N$><7=8vqHY{twC=nXKXl)JDxJvzK1GQ?z8bnA9Vxv|ak}0lTc5`+&oc8pp z>W`$SIj0xUo9LZ*d}ad%YU=)YXWsAU{h0md?O%TbxPrQgPjP7!m$8__S0*J_4P4Xw zbrU1_T9a=~6tQGr*@TI24cstc;Zh3U>GP&0w=}tJpkyMAJKAhTle-4KH<8hj4DJ~y z8(0;v%ATi!k}Jbdg#yWC$8(|^0>kYfrOL|^L+wh(6UgMB#%kM@-i}?30>|4~ic`s8M>`Kt z)4Ayfk$@-*7-3y%$On1sR^+&LwI^hrWT=8YtudDzZ20&1$Tq*;w>SMlTL* z&8puD>gukeYddy;`l7DG!VG2&+_$iX2Ldw{SIJQ2R=h|BISni4|D5Z^DH>R}uz`xe zaqW5pnuQ}J_~#a0;H3qL*?~rj7Phr2uII=|1t$8q zHnv}@ItO$}RQ)ZC)GimvZ&5MX8@l7$6;3?j+?Cwr7-C%ZQ88!S)J87XWimf_TZZ&5 z^@EnZW~(1`YTt=r4=ePRr9Aa(q_4PC@N+}ALygb@v+8pbq?YnTwYuwmG7f7S2>T66D=4WnokWNOJZ-%CHWY_4T& zOFI6jK&8KG72~}GW0qt23>{9K6L5~H>$yOA#w|#J+MMOcC+i>HNN?GAV^dR~b4|m3 zZg`fG50vF9w}3w9IMU15MzJUi1v)*R8>qpBhsS;w^9BCE zt6@&ZJRa-FA+O-^Ug_=BxYkW~+d|@K7n3^|$JBLqc_-{ZX$O2J@ zavAs9WcM~i^3FCQ$?quJ3LGzUt)wH6LNnK2}iZD>kE=e&kn{NIkUtON}abRo&T QobUG?Tp@}wSe44(Kj08{d;kCd literal 0 HcmV?d00001 diff --git a/build/classes/javaside/Socket/TcpClient.class b/build/classes/javaside/Socket/TcpClient.class new file mode 100644 index 0000000000000000000000000000000000000000..6047d5fd6dd4ce7f1ef958a9e878498127437494 GIT binary patch literal 4114 zcmbVP`EwIx7=AWMyJ=XOQfdXtDOVdTDd2@w)K;p|(5i)E@!Td`8VH+^Yyj~-@Ibup z`xcMt=!{L(&iI2f>Wu%3KRe?v>hpfPNwzeC$_(H4?f2f#dwl7ye}4Z1fD7eN#K9frkrc8yYqpB%k=SvP9w9ErFz6sM#XGPh1#aGOvEziC9&Q!iX zo3U(X`ynpZx{TD_n9AmgBBJfl5Z!AzqOBH0u(L~o?$4zyl9L(R8Y~?cvkE)Su`F*| zlev_c9We_T`SvbD&P0ZQy1v%+fp(+C(@ljs6I~;;b)aaa=+|W#JL7EA(BA3B?9Yf| zZ1V`d9Ef~ND#yI094mc?q{?F6f`yXJwX=&M2CO3$*Wx1C?{aTHlCttnCTG*Nb9@H< z_l(P=w)w-3ncBa@%&Tx&w5p&UVVXS48X6R+%A`b8wCpt1)(J#B3T25ZH-;}?Y11(Y zkC{&UGo>Nsir2-{&)F*=M9fsmDi+uD^z>+0eg?^2g~<_eRYW$OU4#`;;odCV7oO2T zwPY*BU#-`Qk}aa->a#03d+c;0h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miQFyY z;TCFgo&AwDCT%?+F8!kNL{De1W^@{BH6dI?L!H3uB0##F8ELE1Wf~F#|Ey zW~Fx5@f*l+-A^R5q!mcDS)DoNB~QQ((%)h=9~-?a2!I2g_j0<8nRF|%1)-*tzxq@> zw|nvYnrp^8l&$aE9H>UuXBx>HAq`4^~6k@CC|D>>TT~pIQ6g`_(LQ8~#EsB7M7A>vNmJdG$#|JBpouTqjhW9kxfneM)N!tJA42A{sUkO?@}1Yb3NqKNMR*~NxVqoB?=Q*MNtnW z6R%9HnOGMvySA5i+_r$I3yej_ZkVr{C<|D1rDRa^>@bv}z~bJC-L*rvEz3>c`6i?C zfpglFL01O(>JDAsyUL9|2rL&yBI~P%0?C@+mI70Iu99Cn-&-;`uv;EiX7+r?_73g9 z)!+Taq*f)cG>W&UA?2%v3`6^fOu1M_*|XJAxfunnI@;-l_83zK(&^mTWe&dDKb1-# zQP5D+S2fQMiB32DPTdv1A&wCmGCKC#7Ajb@a32{96R<2y>(44S zOl(?g(YA@#79Qb^g(rB+(vGNXzABKpmb%|MkxnGAa)(RJbES%QyBxmQs_n@@VEzu= zWz(2u&|$K1(<=lIFEATCH;p^J&BZ*jXJOV^BHc-IZc2eGn)xTd3de zWv|l(o;5t>O-O+fVPrD89RMwR!`qVNJB=CcKH#hd0}0xxV(A>BxNr`m_!EgATr!a5 zI7T3_h8)LPt`SQ6kXFw$C2tY?I@c#`kWQm=#WRRAB!A%^XGZA)V+mZ-QW-&IhNuis z=dP%8c#QcT^#T_A)FpaoG2)sgR=3fku;R@=h2Sx}bo|I*+A(`m(*;c9mZU9~WqW`x d+viJQi3|oyyG)zp59S&32McL%9zWx;`48}o`UU_1 literal 0 HcmV?d00001 diff --git a/build/classes/javaside/Socket/TcpServer$1.class b/build/classes/javaside/Socket/TcpServer$1.class new file mode 100644 index 0000000000000000000000000000000000000000..872b32ff4e6241a1c160bfaaa996db6925a02dbc GIT binary patch literal 1633 zcma)6OH&g;5dH=tE9)W=1RtP+Mh!s?LGVEUMIM3%UqKL5s+P?ttLui^T`2XZc<|uG zvsDT{syuq|2YFNcW;Y62A)2c6O!t1>{dG^zeEsq9Gk_l4uSEk+>S)9%9i2#P=u&G& zM>kIEh@nTRy*kd|tPGX}Ba{Ot`M}h8@%Qr7utu zEZTmeOQ0q9$XqdfyCBo~qV-q?=_zX|FTEA%WeMxIT{{>QIGC(}>zEdZ4HpYipgw22 z^4ju~1?f$h3l1#}xuRt{)23%Dy=083^a2OA4w}d?eYLmjQYOO$KIv`2ci6F|8z=|M zE(nMTfx3KPT8}5qr7$DA7&hXffSxZddzKut6}g?ii#?^nkyZflq} zFoQenLz!UF86+}^jEXU9U=DW;9K=0=Mg>nhru#5G`qYw3fn8*qS}Ft)h;R5zEqc;q zo640CW#z#;wjW4F)lJKiK1ZdC!%}$)<~Gn7h3=_1GvU#vT@GB7Gnzi0VN=NT?+>J; zm@EY>KiRR#IUHKL?T)fV5hJ4-n_v996{GI|V6+_API}1m%x5{afPtfK|7qr=nFY46 zsgyK4i|Y%Iq!na4*oT;JKj(OHayg2>D4bRlM*dBq>}4EX;e?NyZovsJ=Fu$=doxgA zd(j;#wJnyMPz`CXK!BGn#MHC6KjWmzdPM`j8JSfnSoR#+_>ML5NfYt7x;xxe@xKRq z!O7!pkh-$ysm^y0sWnu+2{HRAYls07XrXM5P-w*gYQ%@pc*%Je4wYhk!!}g&+k@0w zi1(;|f%#8}%|_a`Rn)9O%SGDu&Q;XTl=iF8V}*f8+0ps|MiolR7sNY1p>8(Sx`v&r zsHaza=Jook-0St1Zij)2IVnYljPY!nL;n$2C{vCHT92M)(AT(y8I9^TfB)?bDFU2*+ Sj3=<0y9U}CxT;@WwEP4UERYTW literal 0 HcmV?d00001 diff --git a/build/classes/javaside/Socket/TcpServer.class b/build/classes/javaside/Socket/TcpServer.class new file mode 100644 index 0000000000000000000000000000000000000000..56c7af6f753359afd2d185b152680cf65e099096 GIT binary patch literal 2745 zcma)7+fp1=6kTU#pkZh(;VK!EU_=80$#98RU~(ae88Z;gL=?Qlrl*A_lOF7DQuqh{ zg1-60i&c>-A*HFZe9|hvM1R3b8Q1RanQ-YOP{lc?_t|^xwQpzs`tR4@0Gx-{jF)gz zmJek4P?lS=l+tL$?G}851zA4U@JSlYSWKfIOKG&@Qw^Vq&XR`D<@*Z_cQkyNMkfqe zmgUlvo3a>|HCP(HQqT*IW4W^x!}Bapq0zJ4`B`G^-xi4%!*9`9rT2_8@^r1U2*+=l`6?As3k__T1L6x_+)NWC@LtVS1dnNCyTzJ;W!_J zNzGQvq|jcp9czB$-m>N1HkK=tbQY_oQCTotTfQS<%3rk!mx<#RCW4UX`5dY4mEZSVNwvTycppq7PoZBd4tNa9 zr(+xwI^M>N4hL+juHZe`A0Ed!_LUI3iJD2pa8`0xH%)8Zx2tTVOpMR4=!4^8SkoEpJOw!x1EQp1BI9qVoubWfHnS7b*hS;q=r7O|zC#ZWO$xuG zdH!r>7wN4he{WMc893-AE1-*OHwMtd#_eTbeSyOP>J0E^lE0Kmfsgph=?x}A;Y~_g zka&z%4R8I6;}o$IBUTT{NzC%uhiJ(rcaUO&l7FC0wq5AoBeg9l`;(GKXkC1WwjCsR zY+uYgM8^)2TS(1q6YVVC!8DFVlux6HsQpB5=P&DV)-FSh6Vw@?)+x*|!IJb|W`*AC zr1R9Mk?un33C$83-c`V{c@0ybqiGt4^~lp1Z=gRy=OP2>+C{fyEi6l05ZEAz}6OcZxR`BCLzF5-Pex%L??c6bJj{@*c`H4C$MT0c9nF8KM0^EJ^ERHWj6G7rlba zniof+ns@UM)_iVs7kyh#{$VbQlFJ61W9RJ8lIms-l zjwW2e)d*|vq@@lHNjiY3P1-e?G#bChzz$DX@?iSojSI}iVdFzH9&daD#Ta9C1kcRO S9P^rB4UTh96Q+|p|NaMhU@MgX literal 0 HcmV?d00001 diff --git a/build/classes/javaside/Socket/TcpServerEventHandler.class b/build/classes/javaside/Socket/TcpServerEventHandler.class new file mode 100644 index 0000000000000000000000000000000000000000..82fa0799a9d7390f491d5c90ec2a3f5affdc186f GIT binary patch literal 228 zcmZvWy$ZrW5QJxA%#T`FS=bA)F^!#-h@zlaMC{LV3DIyTmopD%;REE_sWX_Qc_ zMX4(n>SX$EB(I9nJ;Q^%Wo&9T%bJy43w18pOqx={s6kbnInA`ZvQ7V*3H{%O{prHe b1_XlVb^|S+(1H&*wh??8Hgt~2T@UdGDPlP- literal 0 HcmV?d00001 diff --git a/dist/JavaSide.jar b/dist/JavaSide.jar new file mode 100644 index 0000000000000000000000000000000000000000..bfc2804f78b6cd15adea3afb1ebcd64cefad3de1 GIT binary patch literal 19057 zcmdU1?ROm4S$}r5t67akmMly1d%U*gH_4JL`CYPQTZ$FS)>|z3y@|7u*0$pHuDrW) z;xuU*N=hl^9oi;9N=u6hq=lrh?9}I!9u7^Rzz6;U_`o@o5B?q}Ab%>6%e9Rq^4GfKHRk!Y{?Xy#<0BK@@!`Zwx=nqJKR1&~#V3>T#PoD>I-Z!z zXKtYQR3eqS9iPPib2F*w8naNKJN|6qRw6euooqje#5fW)W{p|sg3{g+af);-o~;f& z=U}z?t9GSZ@ znaoZkCR2D*Ka{~}oK0kB_-wz7bpGGnSUuZUlshD`O#0Z=RB|?t zY}*G}+Q_8)Q<)qJnB$qb>{N1KhRoMEe6*7ans+=sg>0yEIGMkenKq=)l74yI!b)kh zq)Cn&GGNIQav~%v{T26dF0#)nTH=Q+8I+T}oC-;}H*U$03>z|H$*7E>Cwk*k8T8E* zS3*3Ycuk_VCoMTGFE?%UGC;{2%^hwVEJ(*E|vBz`?6v?ubxWBZ|CyK8~Bi!L)Che zJ7zK+V;H0olU0Eh&DafipFe5NmX`lqTo6VVVTddd`3@`kTh&B%?JXj z*L)0NO3aeI6k6IC#1NXe+U*>FCt@01P3HU6jKsuV>C`)ypGkEb%Vra|hh}nlx9Z~8 z=;7SV3z&WANKE9~Trz(;nV23-=dmmkDcJ?7P%mIxLUnbVcn}s5{F-DX-mX%jBP?Ou z&6d_X5^A|C;kWP;pCvl+QVU}TG3Wf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dist/README.TXT new file mode 100644 index 0000000..234dde9 --- /dev/null +++ b/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "JavaSide.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/manifest.mf b/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml new file mode 100644 index 0000000..221411f --- /dev/null +++ b/nbproject/build-impl.xml @@ -0,0 +1,1420 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties new file mode 100644 index 0000000..3120cfc --- /dev/null +++ b/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=c2254689 +build.xml.script.CRC32=9fd733ac +build.xml.stylesheet.CRC32=8064a381@1.80.1.48 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=c2254689 +nbproject/build-impl.xml.script.CRC32=63684ee5 +nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48 diff --git a/nbproject/private/private.properties b/nbproject/private/private.properties new file mode 100644 index 0000000..bc6d4a5 --- /dev/null +++ b/nbproject/private/private.properties @@ -0,0 +1,2 @@ +compile.on.save=true +user.properties.file=C:\\Users\\Abbas\\AppData\\Roaming\\NetBeans\\8.2\\build.properties diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml new file mode 100644 index 0000000..5ce4d8e --- /dev/null +++ b/nbproject/private/private.xml @@ -0,0 +1,12 @@ + + + + + + file:/D:/Projects/Temp/SocketInVBAndJava/JavaSide/src/javaside/JavaSide.java + file:/D:/Projects/Temp/SocketInVBAndJava/JavaSide/src/javaside/Socket/TcpServerEventHandler.java + file:/D:/Projects/Temp/SocketInVBAndJava/JavaSide/src/javaside/Socket/TcpServer.java + file:/D:/Projects/Temp/SocketInVBAndJava/JavaSide/src/javaside/Socket/TcpClient.java + + + diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..f27af17 --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,74 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processor.options= +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# Files in build.classes.dir which should be excluded from distribution jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/JavaSide.jar +dist.javadoc.dir=${dist.dir}/javadoc +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.external.vm=true +javac.processorpath=\ + ${javac.classpath} +javac.source=1.8 +javac.target=1.8 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=javaside.JavaSide +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..a9206cd --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + JavaSide + + + + + + + + + diff --git a/src/javaside/JavaSide.java b/src/javaside/JavaSide.java new file mode 100644 index 0000000..ae77768 --- /dev/null +++ b/src/javaside/JavaSide.java @@ -0,0 +1,82 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package javaside; + +import java.util.Scanner; +import javaside.Socket.TcpServerEventHandler; +import javaside.Socket.TcpServer; +import javaside.Socket.TcpClientEventHandler; +import javaside.Socket.TcpClient; + +/** + * + * @author Abbas + */ +public class JavaSide { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + // TODO code application logic here + int port = 123; + System.out.println("Please Enter port of server:"); + Scanner scanner = new Scanner(System.in); + port = Integer.parseInt(scanner.nextLine()); + + TcpServer server = new TcpServer(port); + + System.out.println("TCP server start - port:" + port); + + // add event listener + final TcpServer that_server = server; + server.addEventHandler(new TcpServerEventHandler() { + @Override + public void onMessage(int client_id, String line) { + System.out.println("* <" + client_id + "> " + line); + } + + @Override + public void onAccept(int client_id) { + System.out.println("* <" + client_id + "> connection accepted"); + that_server.setReadInterval(100 + that_server.getClients().size() * 10); + } + + @Override + public void onClose(int client_id) { + System.out.println("* <" + client_id + "> closed"); + } + }); + + // start TCP socket server + server.listen(); + + // broadcast + new Thread() { + @Override + public void run() { + while (true) { + try { + Thread.sleep(100); + Scanner scanner = new Scanner(System.in); + String line = scanner.nextLine(); + if (line != null&&!"".equals(line)) { + int data = Integer.parseInt(line); + if (that_server != null && that_server.getClients().size() > 0) { + that_server.getClients().forEach((_item) -> { + _item.send(data); + }); + } + } + } catch (InterruptedException | NumberFormatException ex) { + ex.printStackTrace(); + } + } + } + }.start(); + } + +} diff --git a/src/javaside/Socket/TcpClient.java b/src/javaside/Socket/TcpClient.java new file mode 100644 index 0000000..52f1028 --- /dev/null +++ b/src/javaside/Socket/TcpClient.java @@ -0,0 +1,136 @@ +package javaside.Socket; + +import java.io.*; +import java.net.Socket; +import java.net.SocketException; +import java.net.ConnectException; + +public class TcpClient{ + private String host; + private int port; + private Socket sock; + private int readInterval; + public int getReadInterval(){ return readInterval; } + public void setReadInterval(int msec){ this.readInterval = msec; } + private BufferedWriter bWriter; + private BufferedReader bReader; + private InputStreamReader iReader; + private TcpClientEventHandler handler; + private boolean closer = false; + + public TcpClient(String host, int port){ + this.host = host; + this.port = port; + } + + public TcpClient(Socket connected_socket){ + this.sock = connected_socket; + } + + public boolean run(){ + this.closer = false; + try{ + this.bWriter = new BufferedWriter(new OutputStreamWriter(this.sock.getOutputStream())); + this.iReader = new InputStreamReader(this.sock.getInputStream()); + this.bReader = new BufferedReader(this.iReader); + } + catch(ConnectException ex){ + if(handler != null) handler.onClose(); + return false; + } + catch(Exception ex){ + this.close(); + if(handler != null) handler.onClose(); + return false; + } + final TcpClient that = this; + new Thread(){ + public void run(){ + while(!closer){ + try{ + Thread.sleep(readInterval); + String line = bReader.readLine(); + + if(handler != null) handler.onMessage(line); + + } + catch(SocketException ex){ + that.close(); + } + catch(IOException ex){ + that.close(); + } + catch(Exception ex){ + that.close(); + } + } + } + }.start(); + if(handler != null) handler.onOpen(); + return true; + } + + public boolean connect(){ + if(this.sock != null) return false; + try{ + this.sock = new Socket(host, port); + } + catch(ConnectException ex){ + if(handler != null) handler.onClose(); + return false; + } + catch(Exception ex){ + this.close(); + if(handler != null) handler.onClose(); + return false; + } + return run(); + } + + public void close(){ + try{ + closer = true; + bReader.close(); + bWriter.close(); + iReader.close(); + sock.close(); + sock = null; + if(handler != null) handler.onClose(); + } + catch(Exception ex){ + } + } + + public boolean send(String line){ + if(sock == null) return false; + try{ + bWriter.write(line+"\n"); + bWriter.flush(); + } + catch(Exception ex){ + this.close(); + if(handler != null) handler.onClose(); + return false; + } + return true; + } + + public boolean send(int data){ + if(sock == null) return false; + try{ + bWriter.write(String.valueOf(data)+"\n"); + bWriter.flush(); + } + catch(Exception ex){ + this.close(); + if(handler != null) handler.onClose(); + return false; + } + return true; + } + + public void addEventHandler(TcpClientEventHandler handler){ + this.handler = handler; + } + +} \ No newline at end of file diff --git a/src/javaside/Socket/TcpClientEventHandler.java b/src/javaside/Socket/TcpClientEventHandler.java new file mode 100644 index 0000000..9439835 --- /dev/null +++ b/src/javaside/Socket/TcpClientEventHandler.java @@ -0,0 +1,7 @@ +package javaside.Socket; + +public interface TcpClientEventHandler{ + public void onMessage(String line); + public void onOpen(); + public void onClose(); +} diff --git a/src/javaside/Socket/TcpServer.java b/src/javaside/Socket/TcpServer.java new file mode 100644 index 0000000..eff2b59 --- /dev/null +++ b/src/javaside/Socket/TcpServer.java @@ -0,0 +1,85 @@ +package javaside.Socket; + +import java.io.*; +import java.net.ServerSocket; +import java.net.Socket; +import java.net.SocketException; +import java.net.ConnectException; +import java.util.ArrayList; + +public class TcpServer{ + private ServerSocket server; + private TcpServerEventHandler handler; + private ArrayList clients; + public ArrayList getClients(){ return clients; } + private boolean closer = false; + private int readInterval; + public int getReadInterval(){ return readInterval; } + public void setReadInterval(int msec){ + this.readInterval = msec; + for(TcpClient sock : clients){ + sock.setReadInterval(msec); + } + } + + public TcpServer(int port){ + if(server != null && !server.isClosed()) return; + if(clients == null) clients = new ArrayList(); + try{ + server = new ServerSocket(port); + } + catch(Exception ex){ + } + } + + public void listen(){ + new Thread(){ + public void run(){ + while(!closer){ + try{ + TcpClient sock = new TcpClient(server.accept()); + clients.add(sock); + final int cid = clients.size()-1; // client id + handler.onAccept(cid); + if(handler != null){ + sock.addEventHandler(new TcpClientEventHandler(){ + public void onMessage(String line){ + handler.onMessage(cid, line); + } + public void onOpen(){ + } + public void onClose(){ + handler.onClose(cid); + } + }); + } + sock.run(); + } + catch(Exception ex){ + } + } + } + }.start(); + } + + public TcpClient getClient(int id){ + return clients.get(id); + } + + public void close(){ + closer = true; + try{ + server.close(); + for(TcpClient sock : clients){ + sock.close(); + } + } + catch(Exception ex){ + } + } + + public void addEventHandler(TcpServerEventHandler handler){ + this.handler = handler; + } + +} \ No newline at end of file diff --git a/src/javaside/Socket/TcpServerEventHandler.java b/src/javaside/Socket/TcpServerEventHandler.java new file mode 100644 index 0000000..4acbca0 --- /dev/null +++ b/src/javaside/Socket/TcpServerEventHandler.java @@ -0,0 +1,7 @@ +package javaside.Socket; + +public interface TcpServerEventHandler{ + public void onMessage(int client_id, String line); + public void onAccept(int client_id); + public void onClose(int client_id); +} \ No newline at end of file