Reputation: 325
So, I wrote this chat application which works well in terminal windows: GitHub Source
Now what I want is to convert into a web chat application so that my friends can connect/chat/test it from their network. But, I am clueless about how to proceed!
Please help me. Suggest me which technologies can I use to make it available on a website?
Upvotes: 3
Views: 421
Reputation: 1545
It looks like you've written a Python server to handle your Python chat clients, and you'd like to extend this to web clients.
I would recommend using a real-time network such as PubNub to relay data between your chat clients and the server. Using a real-time network means that you can spend less time worrying about low-level socket issues such as concurrency and more time building your application.
In the case of PubNub, a Python SDK will allow your server to subscribe to chat channels, while the JavaScript SDK will help with web-based clients. You can build a simple JavaScript-based web client using the code in this blog post: Build Real-Time Chat Apps in 10 Lines of Code.
Enter Chat and press enter
<div><input id=input placeholder=you-chat-here /></div>
Chat Output
<div id=box></div>
<script src=http://cdn.pubnub.com/pubnub.min.js></script>
<script>(function(){
var box = PUBNUB.$('box'), input = PUBNUB.$('input'), channel = 'chat';
PUBNUB.subscribe({
channel : channel,
callback : function(text) { box.innerHTML = (''+text).replace( /[<>]/g, '' ) + '<br>' + box.innerHTML }
});
PUBNUB.bind( 'keyup', input, function(e) {
(e.keyCode || e.charCode) === 13 && PUBNUB.publish({
channel : channel, message : input.value, x : (input.value='')
})
} )
})()</script>
Then, on your Python server, you could subscribe to the same chat channel:
# Listen for Messages *BLOCKING*
def receive(message) :
broadcast_data(message) #This is using your Python function from your github link
return True
pubnub.subscribe({
'channel' : 'chat',
'callback' : receive
})
Let me know if this works for you. Good luck!
Upvotes: 3