# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/. from datagramtalk import datagramtalk # This will hanle incoming requests. # As an example we just reply "OK" followed by the original statement def reply_to_message( cmd ): return "OK" + cmd.statement # Initialize the server. # Listen only on localhot, port 4000 # Use function reply_to_message to handle incoming requests. dts = datagramtalk("127.0.0.1", 4000, reply_to_message ) # Wait here for user to want to exit. raw_input( "Press enter to stop...." ) # We need to stop listening before leaving, otherwise the # serving thread will stay in memory. dts.stopListening()
#Get the trackers roster from file try: trackers_urls = open("data/trackers_roster").read().splitlines() except: print "Could not find trackers roster" print "Please create file data/trackers_roster and add trackers to it." sys.exit(1) #And place the valid lines into a list of trackers trackers = [] for tracker_url in trackers_urls: if tracker_url != "": trackers.append(tracker_url) # Open the cache of nodes location nodeslocation = shelve.open("data/nodes_location_" + ownuri) #Distribute the trackers along the ring with 3 replicas for each # this helps to improve distribution. ring = HashRing(trackers, 3) # Initialize the server. dts = datagramtalk('', ownport, reply_to_message) # Wait here for user to want to exit. raw_input("Press enter to stop....") # We need to stop listening before leaving, otherwise the # serving thread will stay in memory. dts.stopListening()
# Get the trackers roster from file try: trackers_urls = open("data/trackers_roster").read().splitlines() except: print "Could not find trackers roster" print "Please create file data/trackers_roster and add trackers to it." sys.exit(1) # And place the valid lines into a list of trackers trackers = [] for tracker_url in trackers_urls: if tracker_url != "": trackers.append(tracker_url) # Open the cache of nodes location nodeslocation = shelve.open("data/nodes_location_" + ownuri) # Distribute the trackers along the ring with 3 replicas for each # this helps to improve distribution. ring = HashRing(trackers, 3) # Initialize the server. dts = datagramtalk("", ownport, reply_to_message) # Wait here for user to want to exit. raw_input("Press enter to stop....") # We need to stop listening before leaving, otherwise the # serving thread will stay in memory. dts.stopListening()
# (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/. from datagramtalk import datagramtalk # This will hanle incoming requests. # As an example we just reply "OK" followed by the original statement def reply_to_message(cmd): return "OK" + cmd.statement # Initialize the server. # Listen only on localhot, port 4000 # Use function reply_to_message to handle incoming requests. dts = datagramtalk("127.0.0.1", 4000, reply_to_message) # Wait here for user to want to exit. raw_input("Press enter to stop....") # We need to stop listening before leaving, otherwise the # serving thread will stay in memory. dts.stopListening()