We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ec308c2 commit c32ba4dCopy full SHA for c32ba4d
tests/client-server/socket-test.py
@@ -0,0 +1,26 @@
1
+# Testing network connection to Google using socket programming
2
+
3
+import socket # for socket
4
+import sys
5
6
+try:
7
+ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
8
+ print ("Socket successfully created")
9
+except socket.error as err:
10
+ print ("socket creation failed with error %s" %(err))
11
12
+# default port for socket
13
+port = 80
14
15
16
+ host_ip = socket.gethostbyname('www.google.com')
17
+except socket.gaierror:
18
19
+ # this means could not resolve the host
20
+ print ("there was an error resolving the host")
21
+ sys.exit()
22
23
+# connecting to the server
24
+s.connect((host_ip, port))
25
26
+print ("the socket has successfully connected to google")
0 commit comments