-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchat_with_online_users.py
66 lines (53 loc) · 1.82 KB
/
chat_with_online_users.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python
# -*- coding: utf-8
# ThePirateWhoSmellsOfSunflowers - https://github.com/ThePirateWhoSmellsOfSunflowers
import Ice
import sys
messagesizemax = "65535"
iceslice = "/usr/share/Ice/slice/Murmur.ice"
iceincludepath = "/usr/share/Ice/slice"
icehost = "127.0.0.1"
iceport = 6502
icesecret = "SheSellsSeashellsOnTheSeeShore"
Ice.loadSlice("--all -I%s %s" % (iceincludepath, iceslice))
props = Ice.createProperties([])
props.setProperty("Ice.MessageSizeMax", str(messagesizemax))
props.setProperty("Ice.ImplicitContext", "Shared")
props.setProperty("Ice.Default.EncodingVersion", "1.0")
id = Ice.InitializationData()
id.properties = props
ice = Ice.initialize(id)
ice.getImplicitContext().put("secret", icesecret)
import Murmur
class CallbacksMurmur(Murmur.ServerCallback):
def __init__(self, server, adapter):
self.server = server
self.adapter = adapter
def userTextMessage(self, user, msg, current=None):
print "\r<%s> : %s" % (user.name,msg.text)
try:
meta = Murmur.MetaPrx.checkedCast(ice.stringToProxy("Meta:tcp -h %s -p %s" % (icehost, iceport)))
except Ice.ConnectionRefusedException:
print 'Could not connect'
ice.shutdown()
sys.exit(1)
try:
server=meta.getServer(1)
except Murmur.InvalidSecretException:
print 'Wrong secret'
ice.shutdown()
sys.exit(1)
adapter = ice.createObjectAdapterWithEndpoints("Callback.Client", "tcp -h %s" % icehost)
adapter.activate()
callback = Murmur.ServerCallbackPrx.uncheckedCast(adapter.addWithUUID(CallbacksMurmur(server, adapter)))
server.addCallback(callback)
while True:
try:
sys.stdout.write('<You> ')
message = sys.stdin.readline()
sys.stdout.flush()
server.sendMessageChannel(0,True,message)
except KeyboardInterrupt:
ice.shutdown()
sys.exit(0)
ice.shutdown()