namespacing

This commit is contained in:
Dan Buch
2012-06-16 00:15:39 -04:00
parent cd8951df52
commit 13e9e7f408
4 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
import socket
import sys
import time
while True:
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(('localhost', 24000))
client.send('PING\n')
sys.stdout.write('client: RECV {}'.format(client.recv(100)))
time.sleep(0.5)

View File

@@ -0,0 +1,11 @@
require 'socket'
loop do
TCPSocket.open('127.0.0.1', 24000) do |sock|
sock.send("PING\n", 0)
pong = sock.recv(100)
puts "client: RECV PONG"
sock.close
end
sleep 0.5
end

View File

@@ -0,0 +1,26 @@
require 'eventmachine'
module PongServer
def post_init
puts "server: Got me a client!"
end
def receive_data(data)
if data =~ /PING/
puts 'server: RECV PING'
send_data("PONG\n")
else
puts "server: RECV #{data}"
send_data("NOPE\n")
end
end
def unbind
puts "server: So long, client!"
end
end
EventMachine::run do
EventMachine::start_server('0.0.0.0', 24000, PongServer)
puts 'Listening on 0.0.0.0:24000'
end

View File

@@ -0,0 +1,15 @@
require 'socket'
server = TCPServer.new('0.0.0.0', 24000)
loop do
Thread.start(server.accept) do |client|
if (ping = client.gets) =~ /PING/
puts 'server: RECV PING'
client.puts("PONG\n")
else
puts "server: RECV #{ping}"
client.puts("NOPE\n")
end
client.close
end
end