Libraryless. Click here for Pure Java version (2155L/16K/50K).
1 | !747 |
2 | |
3 | !1000868 // dialogHandler { |
4 | |
5 | m {
|
6 | static int chatPort = 9751; // just any number, but must match the server's number. |
7 | static S programID; // filled by JavaX |
8 | |
9 | static abstract class DialogIO {
|
10 | abstract boolean isStillConnected(); |
11 | abstract String readLineNoBlock(); |
12 | abstract boolean waitForLine(); |
13 | abstract void sendLine(String line); |
14 | abstract void close(); |
15 | } |
16 | |
17 | p {
|
18 | installHelloMessage(programID + " - Chat client"); |
19 | |
20 | startChatServerIfNotUp(); |
21 | waitForChatServer(); |
22 | |
23 | final Socket s = new Socket("localhost", chatPort);
|
24 | print("connect");
|
25 | |
26 | final Writer w = new OutputStreamWriter(s.getOutputStream(), "UTF-8"); |
27 | final BufferedReader in = new BufferedReader( |
28 | new InputStreamReader(s.getInputStream(), "UTF-8")); |
29 | DialogIO io = new DialogIO() {
|
30 | S line; |
31 | boolean buff; |
32 | |
33 | boolean isStillConnected() {
|
34 | return !(buff || s.isClosed()); |
35 | } |
36 | |
37 | String readLineNoBlock() {
|
38 | S l = line; |
39 | line = null; |
40 | return l; |
41 | } |
42 | |
43 | boolean waitForLine() ctex {
|
44 | if (line != null) return true; |
45 | print("Readline");
|
46 | line = in.readLine(); |
47 | print("Readline done: " + line);
|
48 | if (line == null) buff = true; |
49 | return line != null; |
50 | } |
51 | |
52 | void sendLine(String line) ctex {
|
53 | w.write(line + "\n"); |
54 | w.flush(); |
55 | } |
56 | |
57 | void close() ctex {
|
58 | s.close(); |
59 | } |
60 | }; |
61 | |
62 | //io.waitForLine(); |
63 | io.sendLine("hello chat");
|
64 | print("Sent line.");
|
65 | io.close(); |
66 | print("Closed.");
|
67 | } |
68 | } |
Began life as a copy of #1000867
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1000928 |
| Snippet name: | Chat client |
| Eternal ID of this version: | #1000928/1 |
| Text MD5: | dbe9b8e66a6f0c3d876d226f0162bc8e |
| Transpilation MD5: | 3a76e7eedea886976d786262ee7b5a82 |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX source code |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2015-09-10 00:05:24 |
| Source code size: | 1675 bytes / 68 lines |
| Pitched / IR pitched: | No / Yes |
| Views / Downloads: | 955 / 1016 |
| Referenced in: | [show references] |