@param parent typically use "this" @param host address of the server @param port port to read/write from on the server
(PApplet parent, String host, int port)
| 75 | * @param port port to read/write from on the server |
| 76 | */ |
| 77 | public Client(PApplet parent, String host, int port) { |
| 78 | this.parent = parent; |
| 79 | this.host = host; |
| 80 | this.port = port; |
| 81 | |
| 82 | try { |
| 83 | socket = new Socket(this.host, this.port); |
| 84 | input = socket.getInputStream(); |
| 85 | output = socket.getOutputStream(); |
| 86 | |
| 87 | thread = new Thread(this); |
| 88 | thread.start(); |
| 89 | |
| 90 | parent.registerMethod("dispose", this); |
| 91 | disposeRegistered = true; |
| 92 | |
| 93 | // reflection to check whether host sketch has a call for |
| 94 | // public void clientEvent(processing.net.Client) |
| 95 | // which would be called each time an event comes in |
| 96 | try { |
| 97 | clientEventMethod = |
| 98 | parent.getClass().getMethod("clientEvent", Client.class); |
| 99 | } catch (Exception e) { |
| 100 | // no such method, or an error.. which is fine, just ignore |
| 101 | } |
| 102 | // do the same for disconnectEvent(Client c); |
| 103 | try { |
| 104 | disconnectEventMethod = |
| 105 | parent.getClass().getMethod("disconnectEvent", Client.class); |
| 106 | } catch (Exception e) { |
| 107 | // no such method, or an error.. which is fine, just ignore |
| 108 | } |
| 109 | |
| 110 | } catch (IOException e) { |
| 111 | e.printStackTrace(); |
| 112 | dispose(); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | |
| 117 | /** |
nothing calls this directly
no test coverage detected