javacs 2.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- javacs-2.0.0/LICENSE +21 -0
- javacs-2.0.0/PKG-INFO +120 -0
- javacs-2.0.0/README.md +97 -0
- javacs-2.0.0/javacs/__init__.py +35 -0
- javacs-2.0.0/javacs/calclient.py +47 -0
- javacs-2.0.0/javacs/calserver.py +74 -0
- javacs-2.0.0/javacs/chatclient.py +32 -0
- javacs-2.0.0/javacs/chatserver.py +36 -0
- javacs-2.0.0/javacs/date.py +32 -0
- javacs-2.0.0/javacs/dateclient.py +11 -0
- javacs-2.0.0/javacs/dateserver.py +24 -0
- javacs-2.0.0/javacs/eoclient.py +31 -0
- javacs-2.0.0/javacs/eoserver.py +31 -0
- javacs-2.0.0/javacs/primeclient.py +23 -0
- javacs-2.0.0/javacs/primeserver.py +40 -0
- javacs-2.0.0/javacs/socketclient.py +31 -0
- javacs-2.0.0/javacs/socketserver.py +29 -0
- javacs-2.0.0/javacs.egg-info/PKG-INFO +120 -0
- javacs-2.0.0/javacs.egg-info/SOURCES.txt +22 -0
- javacs-2.0.0/javacs.egg-info/dependency_links.txt +1 -0
- javacs-2.0.0/javacs.egg-info/entry_points.txt +2 -0
- javacs-2.0.0/javacs.egg-info/top_level.txt +1 -0
- javacs-2.0.0/setup.cfg +4 -0
- javacs-2.0.0/setup.py +31 -0
javacs-2.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Chirag Vishwakarma
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
javacs-2.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: javacs
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: Prints Java socket/RMI networking practical programs on demand
|
|
5
|
+
Home-page:
|
|
6
|
+
Author: andhrew
|
|
7
|
+
Author-email: xyz@gmail.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.6
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Dynamic: author
|
|
15
|
+
Dynamic: author-email
|
|
16
|
+
Dynamic: classifier
|
|
17
|
+
Dynamic: description
|
|
18
|
+
Dynamic: description-content-type
|
|
19
|
+
Dynamic: license
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
Dynamic: requires-python
|
|
22
|
+
Dynamic: summary
|
|
23
|
+
|
|
24
|
+
# Java Networking Practicals (`javacs`)
|
|
25
|
+
|
|
26
|
+
A Python package that stores Java networking practical programs (TCP/UDP sockets, chat, broadcast, RPC and RMI) and prints their source code on demand, from Python or the terminal.
|
|
27
|
+
|
|
28
|
+
Install it once with `pip`, then view any program on any machine without copying files around.
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Programs Included
|
|
33
|
+
|
|
34
|
+
| Name | Description |
|
|
35
|
+
|---|---|
|
|
36
|
+
| `calclient` / `calserver` | RPC-style calculator over UDP (`DatagramSocket`) |
|
|
37
|
+
| `chatclient` / `chatserver` | TCP chat between client and server |
|
|
38
|
+
| `dateclient` / `dateserver` | RMI date/time server and client |
|
|
39
|
+
| `eoclient` / `eoserver` | UDP program that checks whether a number is even or odd |
|
|
40
|
+
| `primeclient` / `primeserver` | TCP program that checks whether a number is prime |
|
|
41
|
+
| `socketclient` / `socketserver` | Broadcast server and client |
|
|
42
|
+
| `date` | Extra program |
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## Step 1: Install
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
pip install javacs
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
To update to the latest version:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pip install --upgrade javacs
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Requires Python 3.6 or newer.
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## Step 2: View the programs
|
|
63
|
+
|
|
64
|
+
### Option A: From the terminal
|
|
65
|
+
|
|
66
|
+
Show all programs:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
javacs
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Show a single program:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
javacs chatserver
|
|
76
|
+
javacs primeclient
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Option B: From Python
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
import javacs
|
|
83
|
+
|
|
84
|
+
javacs.show_codes() # Show all programs
|
|
85
|
+
javacs.show_codes("chatserver") # Show one program
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Option C: In Google Colab or Jupyter
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
!pip install javacs
|
|
92
|
+
import javacs
|
|
93
|
+
javacs.show_codes("eoserver")
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## Publishing a new version (for maintainers)
|
|
99
|
+
|
|
100
|
+
1. Make any additions or updates in the `javacs/` folder.
|
|
101
|
+
2. Increment `version` in `setup.py`.
|
|
102
|
+
3. Clean old builds:
|
|
103
|
+
```bash
|
|
104
|
+
rm -rf dist build *.egg-info
|
|
105
|
+
```
|
|
106
|
+
4. Build:
|
|
107
|
+
```bash
|
|
108
|
+
python3 -m build
|
|
109
|
+
```
|
|
110
|
+
5. Check and upload to PyPI:
|
|
111
|
+
```bash
|
|
112
|
+
python3 -m twine check dist/*
|
|
113
|
+
python3 -m twine upload dist/*
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
## License
|
|
119
|
+
|
|
120
|
+
MIT. See [LICENSE](LICENSE).
|
javacs-2.0.0/README.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Java Networking Practicals (`javacs`)
|
|
2
|
+
|
|
3
|
+
A Python package that stores Java networking practical programs (TCP/UDP sockets, chat, broadcast, RPC and RMI) and prints their source code on demand, from Python or the terminal.
|
|
4
|
+
|
|
5
|
+
Install it once with `pip`, then view any program on any machine without copying files around.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Programs Included
|
|
10
|
+
|
|
11
|
+
| Name | Description |
|
|
12
|
+
|---|---|
|
|
13
|
+
| `calclient` / `calserver` | RPC-style calculator over UDP (`DatagramSocket`) |
|
|
14
|
+
| `chatclient` / `chatserver` | TCP chat between client and server |
|
|
15
|
+
| `dateclient` / `dateserver` | RMI date/time server and client |
|
|
16
|
+
| `eoclient` / `eoserver` | UDP program that checks whether a number is even or odd |
|
|
17
|
+
| `primeclient` / `primeserver` | TCP program that checks whether a number is prime |
|
|
18
|
+
| `socketclient` / `socketserver` | Broadcast server and client |
|
|
19
|
+
| `date` | Extra program |
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Step 1: Install
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install javacs
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
To update to the latest version:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install --upgrade javacs
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Requires Python 3.6 or newer.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Step 2: View the programs
|
|
40
|
+
|
|
41
|
+
### Option A: From the terminal
|
|
42
|
+
|
|
43
|
+
Show all programs:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
javacs
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Show a single program:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
javacs chatserver
|
|
53
|
+
javacs primeclient
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Option B: From Python
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
import javacs
|
|
60
|
+
|
|
61
|
+
javacs.show_codes() # Show all programs
|
|
62
|
+
javacs.show_codes("chatserver") # Show one program
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Option C: In Google Colab or Jupyter
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
!pip install javacs
|
|
69
|
+
import javacs
|
|
70
|
+
javacs.show_codes("eoserver")
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## Publishing a new version (for maintainers)
|
|
76
|
+
|
|
77
|
+
1. Make any additions or updates in the `javacs/` folder.
|
|
78
|
+
2. Increment `version` in `setup.py`.
|
|
79
|
+
3. Clean old builds:
|
|
80
|
+
```bash
|
|
81
|
+
rm -rf dist build *.egg-info
|
|
82
|
+
```
|
|
83
|
+
4. Build:
|
|
84
|
+
```bash
|
|
85
|
+
python3 -m build
|
|
86
|
+
```
|
|
87
|
+
5. Check and upload to PyPI:
|
|
88
|
+
```bash
|
|
89
|
+
python3 -m twine check dist/*
|
|
90
|
+
python3 -m twine upload dist/*
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## License
|
|
96
|
+
|
|
97
|
+
MIT. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
def show_codes(filename: str = None):
|
|
5
|
+
"""
|
|
6
|
+
Displays code included in this package.
|
|
7
|
+
- If filename is given (without .py), shows that file's code.
|
|
8
|
+
- If no filename is given, shows all .py files.
|
|
9
|
+
"""
|
|
10
|
+
base_path = os.path.dirname(__file__)
|
|
11
|
+
files = [f for f in os.listdir(base_path) if f.endswith(".py") and f != "__init__.py"]
|
|
12
|
+
|
|
13
|
+
if filename:
|
|
14
|
+
file_path = os.path.join(base_path, f"{filename}.py")
|
|
15
|
+
if os.path.exists(file_path):
|
|
16
|
+
print(f"\n=== Showing {filename}.py ===\n")
|
|
17
|
+
with open(file_path, "r", encoding="utf-8") as f:
|
|
18
|
+
print(f.read())
|
|
19
|
+
else:
|
|
20
|
+
print(f"\n❌ File '{filename}.py' not found in this package.\n")
|
|
21
|
+
print("Available files:")
|
|
22
|
+
for f in files:
|
|
23
|
+
print("•", f.replace(".py", ""))
|
|
24
|
+
else:
|
|
25
|
+
print("\nAll practical codes:\n")
|
|
26
|
+
for f in files:
|
|
27
|
+
print(f"\n=== {f} ===\n")
|
|
28
|
+
with open(os.path.join(base_path, f), "r", encoding="utf-8") as file:
|
|
29
|
+
print(file.read())
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def main():
|
|
33
|
+
"""Command-line entry point: javacs [filename]"""
|
|
34
|
+
filename = " ".join(sys.argv[1:]) or None
|
|
35
|
+
show_codes(filename)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import java.io.*;
|
|
2
|
+
import java.net.*;
|
|
3
|
+
|
|
4
|
+
class RPCClient {
|
|
5
|
+
RPCClient() {
|
|
6
|
+
try {
|
|
7
|
+
InetAddress ia = InetAddress.getLocalHost();
|
|
8
|
+
DatagramSocket ds = new DatagramSocket();
|
|
9
|
+
DatagramSocket ds1 = new DatagramSocket(1300);
|
|
10
|
+
System.out.println("\nRPC Client\n");
|
|
11
|
+
System.out.println(
|
|
12
|
+
"Enter method name and parameters like: add 3 4");
|
|
13
|
+
System.out.println("Type q to quit.\n");
|
|
14
|
+
BufferedReader br = new BufferedReader(
|
|
15
|
+
new InputStreamReader(System.in));
|
|
16
|
+
while (true) {
|
|
17
|
+
String str = br.readLine();
|
|
18
|
+
if (str.equalsIgnoreCase("q")) {
|
|
19
|
+
byte b[] = str.getBytes();
|
|
20
|
+
DatagramPacket dp = new DatagramPacket(
|
|
21
|
+
b, b.length, ia, 1200);
|
|
22
|
+
ds.send(dp);
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
byte b[] = str.getBytes();
|
|
26
|
+
DatagramPacket dp = new DatagramPacket(
|
|
27
|
+
b, b.length, ia, 1200);
|
|
28
|
+
ds.send(dp);
|
|
29
|
+
byte b1[] = new byte[4096];
|
|
30
|
+
DatagramPacket dp1 = new DatagramPacket(
|
|
31
|
+
b1, b1.length);
|
|
32
|
+
ds1.receive(dp1);
|
|
33
|
+
String s = new String(
|
|
34
|
+
dp1.getData(), 0, dp1.getLength());
|
|
35
|
+
System.out.println("\nResult = " + s + "\n");
|
|
36
|
+
}
|
|
37
|
+
ds.close();
|
|
38
|
+
ds1.close();
|
|
39
|
+
} catch (Exception e) {
|
|
40
|
+
e.printStackTrace();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public static void main(String args[]) {
|
|
45
|
+
new RPCClient();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import java.util.*;
|
|
2
|
+
import java.net.*;
|
|
3
|
+
|
|
4
|
+
class RPCServer {
|
|
5
|
+
DatagramSocket ds;
|
|
6
|
+
DatagramPacket dp;
|
|
7
|
+
String str, methodName, result;
|
|
8
|
+
int val1, val2;
|
|
9
|
+
|
|
10
|
+
RPCServer() {
|
|
11
|
+
try {
|
|
12
|
+
ds = new DatagramSocket(1200);
|
|
13
|
+
byte b[] = new byte[4096];
|
|
14
|
+
while (true) {
|
|
15
|
+
dp = new DatagramPacket(b, b.length);
|
|
16
|
+
ds.receive(dp);
|
|
17
|
+
str = new String(
|
|
18
|
+
dp.getData(), 0, dp.getLength());
|
|
19
|
+
if (str.equalsIgnoreCase("q")) {
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
StringTokenizer st = new StringTokenizer(str, " ");
|
|
23
|
+
methodName = st.nextToken();
|
|
24
|
+
val1 = Integer.parseInt(st.nextToken());
|
|
25
|
+
val2 = Integer.parseInt(st.nextToken());
|
|
26
|
+
System.out.println(str);
|
|
27
|
+
if (methodName.equalsIgnoreCase("add")) {
|
|
28
|
+
result = "" + add(val1, val2);
|
|
29
|
+
} else if (methodName.equalsIgnoreCase("sub")) {
|
|
30
|
+
result = "" + sub(val1, val2);
|
|
31
|
+
} else if (methodName.equalsIgnoreCase("mul")) {
|
|
32
|
+
result = "" + mul(val1, val2);
|
|
33
|
+
} else if (methodName.equalsIgnoreCase("div")) {
|
|
34
|
+
if (val2 != 0) {
|
|
35
|
+
result = "" + div(val1, val2);
|
|
36
|
+
} else {
|
|
37
|
+
result = "Division by zero is not allowed";
|
|
38
|
+
}
|
|
39
|
+
} else {
|
|
40
|
+
result = "Invalid method name";
|
|
41
|
+
}
|
|
42
|
+
byte b1[] = result.getBytes();
|
|
43
|
+
DatagramPacket dp1 = new DatagramPacket(
|
|
44
|
+
b1, b1.length,
|
|
45
|
+
dp.getAddress(), 1300);
|
|
46
|
+
System.out.println("Result : " + result + "\n");
|
|
47
|
+
ds.send(dp1);
|
|
48
|
+
}
|
|
49
|
+
ds.close();
|
|
50
|
+
} catch (Exception e) {
|
|
51
|
+
e.printStackTrace();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public int add(int val1, int val2) {
|
|
56
|
+
return val1 + val2;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public int sub(int val1, int val2) {
|
|
60
|
+
return val1 - val2;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public int mul(int val1, int val2) {
|
|
64
|
+
return val1 * val2;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public int div(int val1, int val2) {
|
|
68
|
+
return val1 / val2;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public static void main(String args[]) {
|
|
72
|
+
new RPCServer();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import java.net.*;
|
|
2
|
+
import java.io.*;
|
|
3
|
+
|
|
4
|
+
class ChatClient {
|
|
5
|
+
public static void main(String args[]) {
|
|
6
|
+
try {
|
|
7
|
+
Socket s = new Socket("localhost", 8000);
|
|
8
|
+
BufferedReader br = new BufferedReader(
|
|
9
|
+
new InputStreamReader(System.in));
|
|
10
|
+
DataOutputStream out =
|
|
11
|
+
new DataOutputStream(s.getOutputStream());
|
|
12
|
+
DataInputStream in =
|
|
13
|
+
new DataInputStream(s.getInputStream());
|
|
14
|
+
String msg;
|
|
15
|
+
System.out.println("To stop chatting with server type STOP");
|
|
16
|
+
System.out.print("Client Says: ");
|
|
17
|
+
while ((msg = br.readLine()) != null) {
|
|
18
|
+
out.writeBytes(msg + "\n");
|
|
19
|
+
if (msg.equals("STOP"))
|
|
20
|
+
break;
|
|
21
|
+
System.out.println("Server Says : " + in.readLine());
|
|
22
|
+
System.out.print("Client Says : ");
|
|
23
|
+
}
|
|
24
|
+
br.close();
|
|
25
|
+
in.close();
|
|
26
|
+
out.close();
|
|
27
|
+
s.close();
|
|
28
|
+
} catch (Exception e) {
|
|
29
|
+
e.printStackTrace();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import java.net.*;
|
|
2
|
+
import java.io.*;
|
|
3
|
+
|
|
4
|
+
class ChatServer {
|
|
5
|
+
public static void main(String args[]) {
|
|
6
|
+
try {
|
|
7
|
+
ServerSocket ss = new ServerSocket(8000);
|
|
8
|
+
System.out.println("Waiting for client to connect..");
|
|
9
|
+
Socket s = ss.accept();
|
|
10
|
+
BufferedReader br = new BufferedReader(
|
|
11
|
+
new InputStreamReader(System.in));
|
|
12
|
+
DataOutputStream out =
|
|
13
|
+
new DataOutputStream(s.getOutputStream());
|
|
14
|
+
DataInputStream in =
|
|
15
|
+
new DataInputStream(s.getInputStream());
|
|
16
|
+
String receive, send;
|
|
17
|
+
while ((receive = in.readLine()) != null) {
|
|
18
|
+
if (receive.equals("STOP"))
|
|
19
|
+
break;
|
|
20
|
+
System.out.println("Client Says : " + receive);
|
|
21
|
+
System.out.print("Server Says : ");
|
|
22
|
+
send = br.readLine();
|
|
23
|
+
out.writeBytes(send + "\n");
|
|
24
|
+
if (send.equals("STOP"))
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
br.close();
|
|
28
|
+
in.close();
|
|
29
|
+
out.close();
|
|
30
|
+
s.close();
|
|
31
|
+
ss.close();
|
|
32
|
+
} catch (Exception e) {
|
|
33
|
+
e.printStackTrace();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Practical 2B: XOR function using McCulloch-Pitts Neural Network
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
class McCullochPittsNeuron:
|
|
6
|
+
def __init__(self, weights, threshold):
|
|
7
|
+
self.weights = np.array(weights)
|
|
8
|
+
self.threshold = threshold
|
|
9
|
+
|
|
10
|
+
def activate(self, inputs):
|
|
11
|
+
weighted_sum = np.dot(inputs, self.weights)
|
|
12
|
+
return 1 if weighted_sum >= self.threshold else 0
|
|
13
|
+
|
|
14
|
+
or_neuron = McCullochPittsNeuron(weights=[1, 1], threshold=1)
|
|
15
|
+
nand_neuron = McCullochPittsNeuron(weights=[-2, -2], threshold=-3)
|
|
16
|
+
and_neuron = McCullochPittsNeuron(weights=[1, 1], threshold=2)
|
|
17
|
+
|
|
18
|
+
print("A B | XOR")
|
|
19
|
+
print("------------")
|
|
20
|
+
|
|
21
|
+
inputs = [
|
|
22
|
+
[0, 0],
|
|
23
|
+
[0, 1],
|
|
24
|
+
[1, 0],
|
|
25
|
+
[1, 1]
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
for x in inputs:
|
|
29
|
+
or_output = or_neuron.activate(x)
|
|
30
|
+
nand_output = nand_neuron.activate(x)
|
|
31
|
+
xor_output = and_neuron.activate([or_output, nand_output])
|
|
32
|
+
print(f"{x[0]} {x[1]} | {xor_output}")
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import java.rmi.*;
|
|
2
|
+
import java.io.*;
|
|
3
|
+
|
|
4
|
+
public class ClientDate {
|
|
5
|
+
public static void main(String args[]) throws Exception {
|
|
6
|
+
String s1;
|
|
7
|
+
InterDate h1 = (InterDate) Naming.lookup("rmi://localhost/DS");
|
|
8
|
+
s1 = h1.display();
|
|
9
|
+
System.out.println(s1);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import java.rmi.*;
|
|
2
|
+
import java.rmi.server.*;
|
|
3
|
+
import java.util.*;
|
|
4
|
+
|
|
5
|
+
public class ServerDate extends UnicastRemoteObject
|
|
6
|
+
implements InterDate {
|
|
7
|
+
public ServerDate() throws Exception {
|
|
8
|
+
super();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
public String display() throws Exception {
|
|
12
|
+
String str = "";
|
|
13
|
+
Date d = new Date();
|
|
14
|
+
str = d.toString();
|
|
15
|
+
return str;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public static void main(String args[]) throws Exception {
|
|
19
|
+
ServerDate s1 = new ServerDate();
|
|
20
|
+
Naming.rebind("DS", s1);
|
|
21
|
+
System.out.println(
|
|
22
|
+
"Object registered................................................");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/* Program which finds whether the entered number is even or odd */
|
|
2
|
+
import java.io.*;
|
|
3
|
+
import java.net.*;
|
|
4
|
+
|
|
5
|
+
public class udpClientEO {
|
|
6
|
+
public static void main(String args[]) {
|
|
7
|
+
try {
|
|
8
|
+
DatagramSocket ds = new DatagramSocket(1000);
|
|
9
|
+
BufferedReader br = new BufferedReader(
|
|
10
|
+
new InputStreamReader(System.in));
|
|
11
|
+
System.out.println("Enter a number : ");
|
|
12
|
+
String num = br.readLine();
|
|
13
|
+
byte b[] = num.getBytes();
|
|
14
|
+
DatagramPacket dp = new DatagramPacket(
|
|
15
|
+
b, b.length,
|
|
16
|
+
InetAddress.getLocalHost(), 2000);
|
|
17
|
+
ds.send(dp);
|
|
18
|
+
byte b1[] = new byte[1024];
|
|
19
|
+
DatagramPacket dp1 = new DatagramPacket(
|
|
20
|
+
b1, b1.length);
|
|
21
|
+
ds.receive(dp1);
|
|
22
|
+
String str = new String(
|
|
23
|
+
dp1.getData(), 0, dp1.getLength());
|
|
24
|
+
System.out.println(str);
|
|
25
|
+
br.close();
|
|
26
|
+
ds.close();
|
|
27
|
+
} catch (Exception e) {
|
|
28
|
+
e.printStackTrace();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/* Program which finds whether the entered number is even or odd */
|
|
2
|
+
import java.io.*;
|
|
3
|
+
import java.net.*;
|
|
4
|
+
|
|
5
|
+
public class udpServerEO {
|
|
6
|
+
public static void main(String args[]) {
|
|
7
|
+
try {
|
|
8
|
+
DatagramSocket ds = new DatagramSocket(2000);
|
|
9
|
+
byte b[] = new byte[1024];
|
|
10
|
+
DatagramPacket dp = new DatagramPacket(b, b.length);
|
|
11
|
+
ds.receive(dp);
|
|
12
|
+
String str = new String(
|
|
13
|
+
dp.getData(), 0, dp.getLength());
|
|
14
|
+
System.out.println(str);
|
|
15
|
+
int a = Integer.parseInt(str);
|
|
16
|
+
String s;
|
|
17
|
+
if (a % 2 == 0)
|
|
18
|
+
s = "Number is even";
|
|
19
|
+
else
|
|
20
|
+
s = "Number is odd";
|
|
21
|
+
byte b1[] = s.getBytes();
|
|
22
|
+
DatagramPacket dp1 = new DatagramPacket(
|
|
23
|
+
b1, b1.length,
|
|
24
|
+
dp.getAddress(), dp.getPort());
|
|
25
|
+
ds.send(dp1);
|
|
26
|
+
ds.close();
|
|
27
|
+
} catch (Exception e) {
|
|
28
|
+
e.printStackTrace();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import java.net.*;
|
|
2
|
+
import java.io.*;
|
|
3
|
+
|
|
4
|
+
class tcpClientPrime {
|
|
5
|
+
public static void main(String args[]) {
|
|
6
|
+
try {
|
|
7
|
+
Socket cs = new Socket("localhost", 8001);
|
|
8
|
+
BufferedReader infu = new BufferedReader(
|
|
9
|
+
new InputStreamReader(System.in));
|
|
10
|
+
System.out.println("Enter a number : ");
|
|
11
|
+
int a = Integer.parseInt(infu.readLine());
|
|
12
|
+
DataOutputStream out = new DataOutputStream(cs.getOutputStream());
|
|
13
|
+
out.writeInt(a);
|
|
14
|
+
DataInputStream in = new DataInputStream(cs.getInputStream());
|
|
15
|
+
System.out.println(in.readUTF());
|
|
16
|
+
in.close();
|
|
17
|
+
out.close();
|
|
18
|
+
cs.close();
|
|
19
|
+
} catch (Exception e) {
|
|
20
|
+
System.out.println(e.toString());
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import java.net.*;
|
|
2
|
+
import java.io.*;
|
|
3
|
+
|
|
4
|
+
class tcpServerPrime {
|
|
5
|
+
public static void main(String args[]) {
|
|
6
|
+
try {
|
|
7
|
+
ServerSocket ss = new ServerSocket(8001);
|
|
8
|
+
System.out.println("Server Started..............");
|
|
9
|
+
Socket s = ss.accept();
|
|
10
|
+
DataInputStream in =
|
|
11
|
+
new DataInputStream(s.getInputStream());
|
|
12
|
+
int x = in.readInt();
|
|
13
|
+
DataOutputStream otc =
|
|
14
|
+
new DataOutputStream(s.getOutputStream());
|
|
15
|
+
int y = x / 2;
|
|
16
|
+
boolean prime = true;
|
|
17
|
+
if (x <= 1) {
|
|
18
|
+
prime = false;
|
|
19
|
+
} else {
|
|
20
|
+
for (int i = 2; i <= y; i++) {
|
|
21
|
+
if (x % i == 0) {
|
|
22
|
+
prime = false;
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (prime) {
|
|
28
|
+
otc.writeUTF(x + " is Prime");
|
|
29
|
+
} else {
|
|
30
|
+
otc.writeUTF(x + " is not Prime");
|
|
31
|
+
}
|
|
32
|
+
in.close();
|
|
33
|
+
otc.close();
|
|
34
|
+
s.close();
|
|
35
|
+
ss.close();
|
|
36
|
+
} catch (Exception e) {
|
|
37
|
+
System.out.println(e.toString());
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import java.net.*;
|
|
2
|
+
import java.io.*;
|
|
3
|
+
|
|
4
|
+
public class BroadcastClient {
|
|
5
|
+
public static final int PORT = 1234;
|
|
6
|
+
|
|
7
|
+
public static void main(String args[]) throws Exception {
|
|
8
|
+
MulticastSocket socket;
|
|
9
|
+
DatagramPacket packet;
|
|
10
|
+
InetAddress address;
|
|
11
|
+
|
|
12
|
+
address = InetAddress.getByName("239.1.2.3");
|
|
13
|
+
socket = new MulticastSocket(PORT);
|
|
14
|
+
|
|
15
|
+
socket.joinGroup(address);
|
|
16
|
+
byte[] data = new byte[1024];
|
|
17
|
+
packet = new DatagramPacket(data, data.length);
|
|
18
|
+
for (;;) {
|
|
19
|
+
|
|
20
|
+
socket.receive(packet);
|
|
21
|
+
String str = new String(
|
|
22
|
+
packet.getData(),
|
|
23
|
+
0,
|
|
24
|
+
packet.getLength());
|
|
25
|
+
System.out.println(
|
|
26
|
+
"Message received from "
|
|
27
|
+
+ packet.getAddress());
|
|
28
|
+
System.out.println("Message is : " + str);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import java.net.*;
|
|
2
|
+
import java.io.*;
|
|
3
|
+
import java.util.*;
|
|
4
|
+
|
|
5
|
+
public class BroadcastServer {
|
|
6
|
+
public static final int PORT = 1234;
|
|
7
|
+
|
|
8
|
+
public static void main(String args[]) throws Exception {
|
|
9
|
+
MulticastSocket socket;
|
|
10
|
+
DatagramPacket packet;
|
|
11
|
+
InetAddress address;
|
|
12
|
+
// Set the multicast address
|
|
13
|
+
address = InetAddress.getByName("239.1.2.3");
|
|
14
|
+
socket = new MulticastSocket();
|
|
15
|
+
// Join the multicast group
|
|
16
|
+
socket.joinGroup(address);
|
|
17
|
+
byte[] data;
|
|
18
|
+
for (;;) {
|
|
19
|
+
Thread.sleep(10000);
|
|
20
|
+
System.out.println("Sending");
|
|
21
|
+
String str = "This is Neha Calling......................";
|
|
22
|
+
data = str.getBytes();
|
|
23
|
+
packet = new DatagramPacket(
|
|
24
|
+
data, data.length, address, PORT);
|
|
25
|
+
// Send the packet
|
|
26
|
+
socket.send(packet);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: javacs
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: Prints Java socket/RMI networking practical programs on demand
|
|
5
|
+
Home-page:
|
|
6
|
+
Author: andhrew
|
|
7
|
+
Author-email: xyz@gmail.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.6
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Dynamic: author
|
|
15
|
+
Dynamic: author-email
|
|
16
|
+
Dynamic: classifier
|
|
17
|
+
Dynamic: description
|
|
18
|
+
Dynamic: description-content-type
|
|
19
|
+
Dynamic: license
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
Dynamic: requires-python
|
|
22
|
+
Dynamic: summary
|
|
23
|
+
|
|
24
|
+
# Java Networking Practicals (`javacs`)
|
|
25
|
+
|
|
26
|
+
A Python package that stores Java networking practical programs (TCP/UDP sockets, chat, broadcast, RPC and RMI) and prints their source code on demand, from Python or the terminal.
|
|
27
|
+
|
|
28
|
+
Install it once with `pip`, then view any program on any machine without copying files around.
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Programs Included
|
|
33
|
+
|
|
34
|
+
| Name | Description |
|
|
35
|
+
|---|---|
|
|
36
|
+
| `calclient` / `calserver` | RPC-style calculator over UDP (`DatagramSocket`) |
|
|
37
|
+
| `chatclient` / `chatserver` | TCP chat between client and server |
|
|
38
|
+
| `dateclient` / `dateserver` | RMI date/time server and client |
|
|
39
|
+
| `eoclient` / `eoserver` | UDP program that checks whether a number is even or odd |
|
|
40
|
+
| `primeclient` / `primeserver` | TCP program that checks whether a number is prime |
|
|
41
|
+
| `socketclient` / `socketserver` | Broadcast server and client |
|
|
42
|
+
| `date` | Extra program |
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## Step 1: Install
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
pip install javacs
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
To update to the latest version:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pip install --upgrade javacs
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Requires Python 3.6 or newer.
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## Step 2: View the programs
|
|
63
|
+
|
|
64
|
+
### Option A: From the terminal
|
|
65
|
+
|
|
66
|
+
Show all programs:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
javacs
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Show a single program:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
javacs chatserver
|
|
76
|
+
javacs primeclient
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Option B: From Python
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
import javacs
|
|
83
|
+
|
|
84
|
+
javacs.show_codes() # Show all programs
|
|
85
|
+
javacs.show_codes("chatserver") # Show one program
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Option C: In Google Colab or Jupyter
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
!pip install javacs
|
|
92
|
+
import javacs
|
|
93
|
+
javacs.show_codes("eoserver")
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## Publishing a new version (for maintainers)
|
|
99
|
+
|
|
100
|
+
1. Make any additions or updates in the `javacs/` folder.
|
|
101
|
+
2. Increment `version` in `setup.py`.
|
|
102
|
+
3. Clean old builds:
|
|
103
|
+
```bash
|
|
104
|
+
rm -rf dist build *.egg-info
|
|
105
|
+
```
|
|
106
|
+
4. Build:
|
|
107
|
+
```bash
|
|
108
|
+
python3 -m build
|
|
109
|
+
```
|
|
110
|
+
5. Check and upload to PyPI:
|
|
111
|
+
```bash
|
|
112
|
+
python3 -m twine check dist/*
|
|
113
|
+
python3 -m twine upload dist/*
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
## License
|
|
119
|
+
|
|
120
|
+
MIT. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
setup.py
|
|
4
|
+
javacs/__init__.py
|
|
5
|
+
javacs/calclient.py
|
|
6
|
+
javacs/calserver.py
|
|
7
|
+
javacs/chatclient.py
|
|
8
|
+
javacs/chatserver.py
|
|
9
|
+
javacs/date.py
|
|
10
|
+
javacs/dateclient.py
|
|
11
|
+
javacs/dateserver.py
|
|
12
|
+
javacs/eoclient.py
|
|
13
|
+
javacs/eoserver.py
|
|
14
|
+
javacs/primeclient.py
|
|
15
|
+
javacs/primeserver.py
|
|
16
|
+
javacs/socketclient.py
|
|
17
|
+
javacs/socketserver.py
|
|
18
|
+
javacs.egg-info/PKG-INFO
|
|
19
|
+
javacs.egg-info/SOURCES.txt
|
|
20
|
+
javacs.egg-info/dependency_links.txt
|
|
21
|
+
javacs.egg-info/entry_points.txt
|
|
22
|
+
javacs.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
javacs
|
javacs-2.0.0/setup.cfg
ADDED
javacs-2.0.0/setup.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
import io
|
|
3
|
+
import os
|
|
4
|
+
|
|
5
|
+
def read(fname):
|
|
6
|
+
return io.open(os.path.join(os.path.dirname(__file__), fname), encoding="utf-8").read()
|
|
7
|
+
|
|
8
|
+
setup(
|
|
9
|
+
name="javacs", # must be unique on PyPI
|
|
10
|
+
version="2.0.0",
|
|
11
|
+
author="andhrew",
|
|
12
|
+
author_email="xyz@gmail.com",
|
|
13
|
+
description="Prints Java socket/RMI networking practical programs on demand",
|
|
14
|
+
long_description=read("README.md"),
|
|
15
|
+
long_description_content_type="text/markdown",
|
|
16
|
+
url="", # optional
|
|
17
|
+
packages=find_packages(include=["javacs", "javacs.*"]),
|
|
18
|
+
include_package_data=True,
|
|
19
|
+
install_requires=[],
|
|
20
|
+
entry_points={
|
|
21
|
+
"console_scripts": [
|
|
22
|
+
"javacs=javacs:main",
|
|
23
|
+
],
|
|
24
|
+
},
|
|
25
|
+
license="MIT", # ✅ SPDX-compliant license declaration
|
|
26
|
+
classifiers=[
|
|
27
|
+
"Programming Language :: Python :: 3",
|
|
28
|
+
"Operating System :: OS Independent",
|
|
29
|
+
],
|
|
30
|
+
python_requires=">=3.6",
|
|
31
|
+
)
|