Skip to content

Commit 66867a5

Browse files
committed
exception handling of Sockets with Fore color using colorama module
1 parent 8d961d4 commit 66867a5

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

Web Socket.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
# Program to print a data & it's Metadata of online uploaded file using "socket".
22
import socket
3-
skt_c = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
4-
skt_c.connect(("data.pr4e.org", 80))
5-
link = "GET http://data.pr4e.org/intro-short.txt HTTP/1.0\r\n\r\n".encode()
6-
skt_c.send(link)
3+
from colorama import Fore # this module for Color the font
4+
5+
# handling the exceptions
6+
try:
7+
skt_c = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
8+
skt_c.connect(("data.pr4e.org", 80))
9+
link = "GET http://data.pr4e.org/intro-short.txt HTTP/1.0\r\n\r\n".encode()
10+
skt_c.send(link)
11+
except(Exception) as e:
12+
# this code runes on error in any connection
13+
print(Fore.RED, e, Fore.RESET)
714

815
while True:
916
data = skt_c.recv(512)

0 commit comments

Comments
 (0)