Asynchronous communication between processes through Socket (4)

zhaozj2021-02-16  61

Step 4: Do a more complicated process communication

Both parties that need communication now are threads and are between different processes.

Package com.hode.thread;

/ ** * @Author Tailborn * * Test3 is a thread, in a stand-alone process * Test3 hopes to communicate with threads in another process * one of the other part of Test3 and Socket client states It is the server of the Socket server * * /

public class Test3 extends CommThread implements DealWith {private static Test3 test3 = new Test3 (2000); private SignalSocketThread ssThread = new SignalSocketThread (); public Test3 (int sleepTime) {super (sleepTime); this.setName ( "Test3Thread");} / ** * TEST3 must inherit the Commthread * overwrite Dispose () * Dispose () For the thread you need to handle * / public void dispose () {// Test3 and Socket signal client statement s Arthread.ClientBind (TEST3) } / ** * TEST3 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) {TEST3.THREADSTART ();}}

Ok, now compile this, run Test1 and Test3 to see what effect.

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

New Post(0)