Skip to content

Commit 64d564d

Browse files
author
Bruce Eckel
committed
network etc
1 parent d497920 commit 64d564d

10 files changed

Lines changed: 52 additions & 109 deletions

Checklist.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
[ ] Appendix: Passing & Returning Objects
3333
[ ] Appendix: Logging
3434
[ ] Appendix: Debugging
35-
[ ] Appendix: Network Programming
36-
[ ] Appendix: Remote Methods
35+
[X] Appendix: Network Programming
36+
[X] Appendix: Remote Methods
3737
[ ] Appendix: Profiling and Optimizing
3838
[ ] Appendix: The Benefits and Costs of Static Type Checking
3939
[ ] Appendix: The Positive Legacy of C++ and Java

network/MultiSimpleServer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//: network/MultiSimpleServer.java
22
// ©2015 MindView LLC: see Copyright.txt
3-
// A server that uses multithreading to handle
4-
// any number of clients.
3+
// A server that uses multithreading
4+
// to handle any number of clients.
55
// {ValidateByHand}
66
import java.io.*;
77
import java.net.*;

network/SimpleClient.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,7 @@ public static void main(String[] args)
1414
// special "Local Loopback" IP address, for
1515
// testing on one machine w/o a network:
1616
InetAddress addr =
17-
InetAddress.getByName(null);
18-
// Alternatively, you can use
19-
// the address or name:
20-
// InetAddress addr =
21-
// InetAddress.getByName("127.0.0.1");
22-
// InetAddress addr =
23-
// InetAddress.getByName("localhost");
17+
InetAddress.getLoopbackAddress();
2418
System.out.println("addr = " + addr);
2519
Socket socket =
2620
new Socket(addr, SimpleServer.PORT);

remote/DisplayPerfectTime.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
//: remote/DisplayPerfectTime.java
2+
// ©2015 MindView LLC: see Copyright.txt
23
// Uses remote object PerfectTime
34
// {ValidateByHand}
45
import java.rmi.registry.*;
56

67
public class DisplayPerfectTime {
78
public static void
89
main(String[] args) throws Exception {
9-
Registry reg = LocateRegistry.getRegistry("localhost");
10-
PerfectTime pt = (PerfectTime)reg.lookup("PerfectTime");
10+
Registry reg =
11+
LocateRegistry.getRegistry("localhost");
12+
PerfectTime pt =
13+
(PerfectTime)reg.lookup("PerfectTime");
1114
for(int i = 0; i < 10; i++)
12-
System.out.println("Time: " + pt.getPerfectTime());
15+
System.out.println("Time: "+ pt.getPerfectTime());
1316
}
1417
} ///:~

remote/PerfectTime.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//: remote/PerfectTime.java
2+
// ©2015 MindView LLC: see Copyright.txt
23
// The PerfectTime remote interface
34
import java.rmi.*;
45

remote/PerfectTimeImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//: remote/PerfectTimeImpl.java
2+
// ©2015 MindView LLC: see Copyright.txt
23
// The implementation of the PerfectTime
34
// remote object.
45
import java.rmi.RemoteException;

remote/PerfectTimeServer.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//: remote/PerfectTimeServer.java
2+
// ©2015 MindView LLC: see Copyright.txt
23
// Server for the PerfectTime remote object.
34
// {ValidateByHand}
45
import java.rmi.registry.Registry;
@@ -7,9 +8,11 @@
78
import java.rmi.server.UnicastRemoteObject;
89

910
public class PerfectTimeServer {
10-
public static void main(String[] args) throws RemoteException {
11+
public static
12+
void main(String[] args) throws RemoteException {
1113
PerfectTimeImpl pt = new PerfectTimeImpl();
12-
PerfectTime stub = (PerfectTime)UnicastRemoteObject.exportObject(pt, 0);
14+
PerfectTime stub = (PerfectTime)
15+
UnicastRemoteObject.exportObject(pt, 0);
1316
Registry registry = LocateRegistry.getRegistry();
1417
registry.rebind("PerfectTime", stub);
1518
System.out.println("Ready to do time");

tools/Examples.py

Lines changed: 24 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#! py -3
22
"""
3-
Extract code examples from TIJ4 Refreshed. Extracts from plain text file.
3+
Extract code examples from TIJ Director's Cut plain text file.
44
Creates Ant build.xml file for each subdirectory.
55
"""
66
from pathlib import Path
@@ -64,7 +64,6 @@ def extractExamples():
6464
codeListing.write("\n")
6565

6666

67-
@CmdLine("x")
6867
def clean():
6968
"Remove ExtractedExamples directory"
7069
print("Cleaning ...")
@@ -120,23 +119,22 @@ def show(lines, sep="#"):
120119

121120

122121

123-
def githubDirs():
124-
leader = len(str(github)) + 1
125-
buildfiles = [str(file)[leader:] for file in github.glob("**/build.xml")]
126-
return {str((github / f).parent)[leader:] for f in buildfiles}
122+
# def githubDirs():
123+
# leader = len(str(github)) + 1
124+
# buildfiles = [str(file)[leader:] for file in github.glob("**/build.xml")]
125+
# return {str((github / f).parent)[leader:] for f in buildfiles}
127126

128127

129-
def destDirs(pattern="**"):
130-
leader = len(str(destination)) + 1
131-
return {str(file)[leader:] for file in destination.glob(pattern)}
128+
# def destDirs(pattern="**"):
129+
# leader = len(str(destination)) + 1
130+
# return {str(file)[leader:] for file in destination.glob(pattern)}
132131

133132

134133

135-
@CmdLine("a")
136134
def copySupplementalFilesFromGithub():
137135
"Copy supplemental files from Github repository to extracted examples"
138136
print("Copying supplemental files from Github ...")
139-
def _copy(dir, name_or_pattern, trace=False):
137+
def _copy_from_github(dir, name_or_pattern, trace=False):
140138
source = (github/dir).glob(name_or_pattern)
141139
dest_dir = examples/dir
142140
assert dest_dir.is_dir()
@@ -145,14 +143,15 @@ def _copy(dir, name_or_pattern, trace=False):
145143
print("source: {}".format(f))
146144
print("dest: {}".format(dest_dir))
147145
shutil.copy(str(f), str(dest_dir))
148-
149-
_copy(".", "build.xml")
150-
_copy(".", "Ant-*.xml")
151-
_copy("gui", "*.gif")
152-
_copy("network", "*.bat")
153-
_copy("network", "build.xml")
154-
_copy("remote", "*.bat")
155-
_copy("remote", "build.xml")
146+
for args in [
147+
(".", "build.xml"),
148+
(".", "Ant-*.xml"),
149+
("gui", "*.gif"),
150+
("network", "*.bat"),
151+
("network", "build.xml"),
152+
("remote", "*.bat"),
153+
("remote", "build.xml"),
154+
]: _copy_from_github(*args)
156155

157156
patterns = destination / "patterns"
158157
trash = patterns / "recycleap" / "Trash.dat"
@@ -339,25 +338,9 @@ def makeBuildFile(self):
339338
</exec>
340339
"""
341340

342-
# def addBatchCommand(target_dir, batch_file_name):
343-
# with (destination/target_dir/"build.xml").open() as build:
344-
# lines = build.readlines()
345-
# for n, line in enumerate(lines):
346-
# if "</target>" in line:
347-
# lines.insert(n, exec.format(batch_file_name, batch_file_name))
348-
# break
349-
# with (destination/target_dir/"build.xml").open("w") as build:
350-
# build.writelines(lines)
351-
352-
# def addBatchFile(target_dir, batch_file_name, batch_file_text):
353-
# with (destination/target_dir/batch_file_name).open('w') as ss:
354-
# ss.write(batch_file_text)
355-
# addBatchCommand(target_dir, batch_file_name)
356-
357-
358-
@CmdLine("m")
341+
#@CmdLine("m")
359342
def createAntFiles():
360-
"Make ant files that don't exist"
343+
"Make ant files"
361344
print("Creating Ant Files ...")
362345
chapters = [Chapter(fd) for fd in destination.glob("*") if fd.is_dir() if not (fd / "build.xml").exists()]
363346
for chapter in chapters:
@@ -393,7 +376,6 @@ def extractAndCreateBuildFiles():
393376
run.write(r"python ..\Validate.py -e" + "\n")
394377

395378

396-
@CmdLine('g')
397379
def generateAntClean():
398380
"Generate directives for Ant-Clean.xml"
399381
others = set([f.name for f in examples.rglob("*") if not f.is_dir()
@@ -408,11 +390,10 @@ def generateAntClean():
408390
for f in others:
409391
print(""" <exclude name="**/{}" />""".format(f))
410392

411-
# pprint.pprint([f for f in others if "test" in f or "Test" in f])
412393

413-
tagRE = re.compile("{.*?}", re.DOTALL)
414394

415395
def findTags(lines):
396+
tagRE = re.compile("{.*?}", re.DOTALL)
416397
topblock = []
417398
for line in lines:
418399
if line.startswith("//"):
@@ -442,4 +423,6 @@ def findAllCommentTags():
442423

443424

444425

445-
if __name__ == '__main__': CmdLine.run()
426+
if __name__ == '__main__':
427+
print(__doc__)
428+
CmdLine.run()

tools/Validate.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#! py -3
22
"""
33
Run all (possible) java files and capture output and errors
4+
"""
5+
TODO = """
6+
- 1st and last 10 lines, with ... in between? {FirstAndLast: 10 Lines}
47
5-
TODO: 1st and last 10 lines, with ... in between? {FirstAndLast: 10 Lines}
6-
7-
TODO: format __newOutput() for line width using textwrap
8+
- format __newOutput() for line width using textwrap
89
"""
910
from pathlib import Path
1011
import pprint

tools/update_git.py

Lines changed: 6 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#! Py -3
2+
"Tools for updating Github repository"
23
from pathlib import Path
34
from filecmp import cmpfiles
45
from filecmp import dircmp
@@ -8,7 +9,9 @@
89
from pprint import *
910

1011
gitpath = Path(r"C:\Users\Bruce\Documents\GitHub\TIJ-Directors-Cut")
12+
assert gitpath.is_dir()
1113
examplePath = Path(r"C:\Users\Bruce\Dropbox\__TIJ4-ebook\ExtractedExamples")
14+
assert examplePath.is_dir()
1215

1316
def ignore(lst):
1417
result = [f for f in lst if not str(f).startswith(".git")]
@@ -23,7 +26,7 @@ def ignore(lst):
2326

2427
@CmdLine('g')
2528
def copy_to_git():
26-
"Write batch file to copy missing files to git directory"
29+
"Write togit.bat to copy missing files to git directory"
2730
exclude = ["Book.txt", "Git.txt", "togit.bat"]
2831
os.chdir(str(examplePath))
2932
with Path("togit.bat").open("w") as togit:
@@ -56,33 +59,11 @@ def diff():
5659
"Show differences with git directory"
5760
os.chdir(str(examplePath))
5861
os.system("diff -q -r . " + str(gitpath))
59-
# common = [str(b) for b in book if not b.is_dir()]
60-
# dcmp = dircmp(str(examplePath), str(gitpath))
61-
# print_diff_files(dcmp)
62-
# print(dcmp.right_only)
63-
# with Path("clean.bat").open('w') as outfile:
64-
# outfile.write("\n" + ruler("match"))
65-
# outfile.write(pformat(match))
66-
# outfile.write("\n" + ruler("mismatch"))
67-
# outfile.write(pformat(mismatch))
68-
# outfile.write("\n" + ruler("errors"))
69-
# outfile.write(pformat(errors))
70-
# head("files to update")
71-
# for f in mismatch:
72-
# outfile.write("copy {} {}\{}\n".format(f, str(gitpath), f))
73-
# print(f)
74-
75-
# os.chdir(str(gitpath))
76-
# with Path("clean.bat").open("w") as clean:
77-
# toclean = retain([g for g in git if g not in book])
78-
# for tc in toclean:
79-
# clean.write("del " + str(tc) + "\n")
80-
# if Path("clean.bat").stat().st_size == 0:
81-
# Path("clean.bat").unlink()
62+
8263

8364
@CmdLine('u')
8465
def update_to_git():
85-
"Write batch file to copy out-of-date files to git directory"
66+
"Write update.bat to copy out-of-date files to git directory"
8667
os.chdir(str(examplePath))
8768
os.system("diff -q -r . " + str(gitpath) + " > update.bat")
8869
lines = [line[len("Files "):-(len("differ") + 1)] for line in open("update.bat").readlines() if line.startswith("Files ")]
@@ -99,30 +80,6 @@ def update_to_git():
9980
update.write("\n".join(lines))
10081

10182

102-
# os.chdir(str(examplePath))
103-
# common = [str(b) for b in book if not b.is_dir()]
104-
# match, mismatch, errors = cmpfiles(str(examplePath), str(gitpath), common, False)
105-
# with Path("update.bat").open('w') as outfile:
106-
# # outfile.write("\n" + ruler("match"))
107-
# # outfile.write(pformat(match))
108-
# # outfile.write("\n" + ruler("mismatch"))
109-
# # outfile.write(pformat(mismatch))
110-
# # outfile.write("\n" + ruler("errors"))
111-
# # outfile.write(pformat(errors))
112-
# head("files to update")
113-
# for f in mismatch:
114-
# outfile.write("copy {} {}\{}\n".format(f, str(gitpath), f))
115-
# print(f)
116-
117-
# head("odd files")
118-
# for f in mismatch:
119-
# if not (f.endswith(".java") or
120-
# f.endswith(".py") or
121-
# f.endswith(".cpp") or
122-
# f.endswith("build.xml")):
123-
# print(f)
124-
125-
12683
def comment_header(lines):
12784
if lines[0][0] == "#":
12885
cmt = "#"

0 commit comments

Comments
 (0)