Asynchronous communication between processes through Socket (3)

xiaoxiao2021-03-06  64

Step 3: Write test code

//Test1.java

Package com.hode.thread;

/ ** * @Author Tai Bozi * * Test1 creates a general thread, and the server of the socket signal Bond * This means that the test1 thread can communicate via Socket * / public class test1 extends commthread {

/ ** * TEST1 must inherit the general thread Commthread * Commthread is a virtual base class, must override the function dispose () * / public test1 (SleepTime); this.setname ("Test1thRead");} / * * * Overwritten Dispose () * Dispose () For things that need to be processed in the thread * / public void dispose () {for (int i = 0; i <10; i ) {THREAD.SLEP (500);} catch (InterruptedException e) {} System.out.print (i "");}} public static void main (String [] args) {test1 test1 = new test1 (2000); SignalSocketThread ssThread = new SignalSocketThread (); // Test1 and Socket signals of the server Bonds SSTHREAD.SERVERBIND (TEST1); // Start the server thread Test1.ThreadStart () of the thread Test1 and Socket signals, respectively, respectively, SSTHREAD.THREADSTART ()

//Test2.java

Package com.hode.thread;

/ ** * @Author Tailborn * * Test2 is a process that hopes to communicate with another process * where Test2 and Socket client statement is the other party of communication, the other party of Socket is the server of the Socket * * / public class test2 imports dealwith {

/ ** * TEST1 must inherit the interface dealWith * Implement function DEALWITH () * / public void dealWith () {for (int i = 0; i <10; i ) {THREAD.SLEP (500);} catch (InterruptedException) e) {} system.out.print (i ");}}}} public static void main (string [] args) {test2 test2 = new test2 (); signthalog ketteread ssthread = new signalsocketthread (); // Customer with Socket Derobang SSTHREAD.CLIENTBIND (TEST2);}} It is now compiled to run Test1 and Test2.

转载请注明原文地址:https://www.9cbs.com/read-119030.html

New Post(0)