-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Version 1.0 Open the Py file to read the code and its description Still learning how to use GitHub so bear with me
- Loading branch information
0 parents
commit 11cf844
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
''' | ||
EthanGo v1.0 | ||
Super simple socket program. No security. No privacy. | ||
Do not run for prolonged periods of time. | ||
Issues: | ||
- Each sender must take turns sending messages | ||
- Client will crash if server not up | ||
- Simple terminal chat is not cool | ||
Written by Julio Medeiros | ||
10/03/2022 | ||
''' | ||
|
||
import socket | ||
|
||
version = 1.0 | ||
|
||
HOST = "127.0.0.1" #input("Server's IP adress: ") # The server's hostname or IP address | ||
PORT = 14099 # The port used by the server | ||
|
||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
s.connect((HOST, PORT)) | ||
while True: | ||
msg = bytes(input("Me> "), "utf-8") ## Get msg to send from user and convert into bytes | ||
s.sendall(msg) ## Send message to server | ||
data = s.recv(1024) ## Receive any messages sent from server | ||
print("Them> ", data.decode("utf-8") ) ## Decode messages sent from server | ||
|
||
print(f"Received {data!r}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
''' | ||
EthanGo v1.0 | ||
Super simple socket program. No security. No privacy. | ||
Do not run for prolonged periods of time. | ||
Issues: | ||
- Each sender must take turns sending messages | ||
- Client will crash if server not up | ||
- Simple terminal chat is not cool | ||
Written by Julio Medeiros | ||
10/03/2022 | ||
''' | ||
|
||
import socket | ||
|
||
version = 1.0 | ||
|
||
HOST = "127.0.0.1" # Standard loopback interface address (localhost) | ||
PORT = 14099 # High port to evade scans | ||
|
||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
s.bind((HOST, PORT)) | ||
s.listen() | ||
conn, addr = s.accept() | ||
with conn: | ||
print(f"Connected by {addr}") | ||
while True: | ||
data = conn.recv(1024) ## Receive messages from client | ||
if not data: ## If data is null, connection broken > END | ||
break | ||
print("Them> ", data.decode("utf-8") ) ## If data exists, decode and display | ||
msg = bytes(input("Me> "), "utf-8") ## Collect msg to send from server in bytes | ||
conn.sendall(msg) ## Send msg to client |