#!/usr/bin/python
# Demo server to open port 9999
# Modified from Python tutorial docs
import socket
import sys
HOST = 'localhost' # IP addresses or Hostname
PORT = 9999 # Open non-privileged port 9999
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print 'Socket created Successfully'
#Bind socket to local host and port
try:
s.bind((HOST, PORT))
except socket.error as msg:
print 'Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1]
sys.exit()
print 'Socket bind complete'
#Started listening on socket
s.listen(10)
print 'Socket now listening'
while 1:
#waiting to accept a connection - blocking call
conn, addr = s.accept()
print 'Connected with ' + addr[0] + ':' + str(addr[1])
s.close()
save the above file as port_server.py
run the port_server.py in one terminal & try telnet the hostname with 9999
# Demo server to open port 9999
# Modified from Python tutorial docs
import socket
import sys
HOST = 'localhost' # IP addresses or Hostname
PORT = 9999 # Open non-privileged port 9999
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print 'Socket created Successfully'
#Bind socket to local host and port
try:
s.bind((HOST, PORT))
except socket.error as msg:
print 'Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1]
sys.exit()
print 'Socket bind complete'
#Started listening on socket
s.listen(10)
print 'Socket now listening'
while 1:
#waiting to accept a connection - blocking call
conn, addr = s.accept()
print 'Connected with ' + addr[0] + ':' + str(addr[1])
s.close()
run the port_server.py in one terminal & try telnet the hostname with 9999
Thank you for providing this useful information.
ReplyDeleteOracle dba Training