Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #50823 > unrolled thread

What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project)

Started byAseem Bansal <asmbansal2@gmail.com>
First post2013-07-17 21:36 -0700
Last post2013-07-19 17:17 +1000
Articles 11 on this page of 31 — 13 participants

Back to article view | Back to comp.lang.python


Contents

  What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project) Aseem Bansal <asmbansal2@gmail.com> - 2013-07-17 21:36 -0700
    Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project) vikash agrawal <vikashagrawal1990@gmail.com> - 2013-07-18 10:22 +0530
      Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project) Aseem Bansal <asmbansal2@gmail.com> - 2013-07-17 23:11 -0700
        Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project) Chris Angelico <rosuav@gmail.com> - 2013-07-18 16:25 +1000
          Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project) Aseem Bansal <asmbansal2@gmail.com> - 2013-07-17 23:36 -0700
            Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project) Andrew Berg <robotsondrugs@gmail.com> - 2013-07-18 01:49 -0500
              Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project) Aseem Bansal <asmbansal2@gmail.com> - 2013-07-18 00:05 -0700
                Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project) Chris Angelico <rosuav@gmail.com> - 2013-07-18 17:13 +1000
                  Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project) Aseem Bansal <asmbansal2@gmail.com> - 2013-07-18 00:29 -0700
                    Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project) Chris Angelico <rosuav@gmail.com> - 2013-07-18 17:34 +1000
                      Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project) Aseem Bansal <asmbansal2@gmail.com> - 2013-07-18 00:48 -0700
                        Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project) Chris Angelico <rosuav@gmail.com> - 2013-07-18 17:52 +1000
                          Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project) Aseem Bansal <asmbansal2@gmail.com> - 2013-07-18 01:10 -0700
                            Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project) Chris Angelico <rosuav@gmail.com> - 2013-07-18 18:37 +1000
                        Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project) aseem bansal <aseembansal@ymail.com> - 2013-07-18 01:04 -0700
                    Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project) Terry Reedy <tjreedy@udel.edu> - 2013-07-18 13:04 -0400
                    Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project) Serhiy Storchaka <storchaka@gmail.com> - 2013-07-18 20:55 +0300
                      Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project) Grant Edwards <invalid@invalid.invalid> - 2013-07-18 18:02 +0000
                        Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project) Owen Marshall <o@owenmarshall.invalid> - 2013-07-18 18:19 +0000
                          Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project) Michael Torrie <torriem@gmail.com> - 2013-07-18 16:40 -0600
                            Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project) Owen Marshall <o@owenmarshall.invalid> - 2013-07-19 00:54 +0000
            Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project) Chris Angelico <rosuav@gmail.com> - 2013-07-18 16:49 +1000
          Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project) Grant Edwards <invalid@invalid.invalid> - 2013-07-18 13:00 +0000
          Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project) Jorgen Grahn <grahn+nntp@snipabacken.se> - 2013-07-19 11:25 +0000
            Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project) Chris Angelico <rosuav@gmail.com> - 2013-07-19 21:56 +1000
    Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project) "Eric S. Johansson" <esj@harvee.org> - 2013-07-18 01:39 -0400
      Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project) Aseem Bansal <asmbansal2@gmail.com> - 2013-07-17 22:50 -0700
    Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project) Chris Angelico <rosuav@gmail.com> - 2013-07-18 16:15 +1000
    Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project) Michael Torrie <torriem@gmail.com> - 2013-07-18 16:34 -0600
    Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project) Jake Angulo <jake.angulo@gmail.com> - 2013-07-19 17:10 +1000
    Re: What does it take to implement a chat system in Python (Not asking for code just advice before I start my little project) Chris Angelico <rosuav@gmail.com> - 2013-07-19 17:17 +1000

Page 2 of 2 — ← Prev page 1 [2]


#50882

FromOwen Marshall <o@owenmarshall.invalid>
Date2013-07-19 00:54 +0000
Message-ID<slrnkuh3hh.16u8.o@owen-marshall-4.local>
In reply to#50873
On 2013-07-18, Michael Torrie <torriem@gmail.com> wrote:
> On 07/18/2013 12:19 PM, Owen Marshall wrote:
>> Huh - I (foolishly) didn't realize gmane actually had NNTP, I've always
>> used it to search mailing lists. If the list dumped to usenet (much like
>> c.l.python) I'd post through sunsite.dk, which is a very nice usenet
>> provider. But that still meant several annoying mailing list
>> subscriptions.
>>
>> ... man, I'm really glad I read your post :-)
>
> I'm a bit confused.  This list *is* c.l.python (I happen to read via
> e-mail through the mailing list).  So you can reach it from sunsite.dk
> can you not?

Doesn't surprise me, I was confusing ;-)

What I was saying was that my workflow used to be this:

For maliing lists that dump to a newsgroup (c.l.python) I'd post to the
group via usenet (sunsite.dk)

For mailing lists that _do not_ have a direct newsgroup gateway (flask,
etc.) I'd have to subscribe and read them in my mail client.


So I used to think gmane was just a way of reading a bunch of mailing
lists. *But now* I know it is much more - it's an NNTP <==> mail gateway
that also has a web viewer.

Now I can point my slrn to news.gmane.net and see the flask mailing
list, ruby-talk, ... -- which I much prefer to using email.


Again, perfectly obvious stuff had I actually _read_ the gmane FAQ. But
who has time for that ;-)

--
      -owen

[toc] | [prev] | [next] | [standalone]


#50837

FromChris Angelico <rosuav@gmail.com>
Date2013-07-18 16:49 +1000
Message-ID<mailman.4829.1374130189.3114.python-list@python.org>
In reply to#50835
On Thu, Jul 18, 2013 at 4:36 PM, Aseem Bansal <asmbansal2@gmail.com> wrote:
> @Chris Angelico
>
> Thanks. That cleared many doubts and your suggestions would definitely be useful.
>
> I am asking the next paragraph because you said about Python 3 helping with things. I am not looking for a debate or anything just a opinion.
>
> I learnt Python myself and everyone told me that Python 2 is status quo so I learned Python 2 and have been working with it. I am just 1.5 months in Python programming so should I consider switching to Python 3 if it helps with new things or should I stick with Python 2 to get a taste of what is currently out there?

Python 3 is now the current Python. There'll be no more development on
Python 2 (bugfixes/security only, and even that won't be forever), so
I strongly recommend going to Python 3. You're writing new code, so
there's really no reason to use Python 2. All the core libraries
you'll be needing (socket, mainly) are available for Py3, and as I
mentioned earlier, Unicode handling is far superior (especially as of
3.3).

> About Pike, thanks for the heads up. But for now I'll use Python. I wanted to learn Python through this project. I'll leave Pike for later. Maybe Phase 1.5.

Yep. My main point there is: Don't be too stuck on any one tool, learn
'em all. Learn Python now, you may find that you want to use Pike
later. Build your system so you can switch one thing out for another.

> Aren't you guys posting in google groups? I thought you were because I can see your posts here. How do I post in python mailing list and see its archives instead of posting on google groups?

Google Groups is one way (and one of the worse ways) of accessing
comp.lang.python, which is cross-mirrored with the mailing list
python-list@python.org - the easiest way is to simply subscribe to
either the newsgroup or the mailing list, using a newsreader or mail
client. As you see, I'm posting from gmail; there are a couple of
issues with using gmail here (it doesn't have a "Reply List" option,
for instance), but it's orders of magnitude less annoying than Google
Groups.

ChrisA

[toc] | [prev] | [next] | [standalone]


#50855

FromGrant Edwards <invalid@invalid.invalid>
Date2013-07-18 13:00 +0000
Message-ID<ks8otr$mil$1@reader2.panix.com>
In reply to#50834
On 2013-07-18, Chris Angelico <rosuav@gmail.com> wrote:
> On Thu, Jul 18, 2013 at 4:11 PM, Aseem Bansal <asmbansal2@gmail.com> wrote:
>> @vikash agrawal
>>
>> About GUI I discussed it at https://groups.google.com/forum/#!starred/comp.lang.python/M-Dy2pyWRfM and I am thinking about using PySide 1.2 for clients of chat system. I think I'll need downloadable clients if I want to make something like google talk. Then I'll need to implement server side programming also. I think google app engine would be suitable for this as it is going to be always online.
>
> Hrm. Rather than pointing people to Google Groups, which a number here
> (and not unreasonably) detest, you may want to link to the python-list
> archive:
>
> http://mail.python.org/pipermail/python-list/2013-July/thread.html#651359

While that's the canonical archive, the UI is awful.  I find gmane's
web UI to be _far_ more friendly and useful than the pipermail archive
UI:

http://thread.gmane.org/gmane.comp.python.general/737271/

 1) The search facility sort-of works (though using google with
    site:gmane.org:/gmane.comp.python usually works better).

 2) You can post from the gmane web UI.

 3) It offers both a threaded and a flat, blog-like version.

-- 
Grant Edwards               grant.b.edwards        Yow! We just joined the
                                  at               civil hair patrol!
                              gmail.com            

[toc] | [prev] | [next] | [standalone]


#50896

FromJorgen Grahn <grahn+nntp@snipabacken.se>
Date2013-07-19 11:25 +0000
Message-ID<slrnkui8h5.2m9.grahn+nntp@frailea.sa.invalid>
In reply to#50834
On Thu, 2013-07-18, Chris Angelico wrote:
...
> You can certainly do your server-side programming directly in Python;
> in fact, I recommend it for this task. There's no reason to use HTTP,
> much less a web framework (which usually consists of a structured way
> to build HTML pages, plus a bunch of routing and stuff, none of which
> you need). All you need is a simple structure for separating one
> message from another.

> I would recommend either going MUD/TELNET style
> and ending each message with a newline, or prefixing each message with
> its length in octets. Both ways work very nicely; newline-termination
> allows you to use a MUD client for debugging, which I find very
> convenient

It's definitely the way to go.  It's not just MUDs -- a lot of
Internet protocols work that way.  Netcat is one popular client for
talking to/debugging/testing such servers.  No doubt MUD clients too,
but last time I did such stuff was in 1993, and I think I used telnet
...

In fact, I'd design the protocol before starting to write code.  Or
better, steal some existing chat protocol.  Like a subset of IRC.


There's also another question in the original posting that bothers me:
paraphrased "do I need to learn database programming to manage users"?
No!  Unix does fine with plain-text files.

Managing credentials (understanding cryptography, setting up a support
organization for resetting lost passwords ...) is non-trivial though,
so try to do without such things at first.  It's not obvious that you
should need an account for an experimental chat, anyway.

/Jorgen

-- 
  // Jorgen Grahn <grahn@  Oo  o.   .     .
\X/     snipabacken.se>   O  o   .

[toc] | [prev] | [next] | [standalone]


#50897

FromChris Angelico <rosuav@gmail.com>
Date2013-07-19 21:56 +1000
Message-ID<mailman.4863.1374235007.3114.python-list@python.org>
In reply to#50896
On Fri, Jul 19, 2013 at 9:25 PM, Jorgen Grahn <grahn+nntp@snipabacken.se> wrote:
> On Thu, 2013-07-18, Chris Angelico wrote:
> ...
>> You can certainly do your server-side programming directly in Python;
>> in fact, I recommend it for this task. There's no reason to use HTTP,
>> much less a web framework (which usually consists of a structured way
>> to build HTML pages, plus a bunch of routing and stuff, none of which
>> you need). All you need is a simple structure for separating one
>> message from another.
>
>> I would recommend either going MUD/TELNET style
>> and ending each message with a newline, or prefixing each message with
>> its length in octets. Both ways work very nicely; newline-termination
>> allows you to use a MUD client for debugging, which I find very
>> convenient
>
> It's definitely the way to go.  It's not just MUDs -- a lot of
> Internet protocols work that way.  Netcat is one popular client for
> talking to/debugging/testing such servers.  No doubt MUD clients too,
> but last time I did such stuff was in 1993, and I think I used telnet

Yeah. As I mentioned, I'm a MUDder with tens of thousands of online
hours on Threshold RPG[1], and have written several MUD clients; in
fact, I'm right now working on Gypsum (fun fun). The most common
internet protocols all:
* Involve a well-known TCP port and a single socket connection (apart from FTP)
* Begin with a one-line (usually) greeting from the server
* Have a line-based request-and-response system
* Have normal lines divided into "command" and "parameters" as per
shell commands
* (Usually) have an easy way to recognize success/failure, even
without understanding the whole response
* Are human-readable to the extreme
* Rely on lower-level protocols for encryption (eg TLS)

The mail trilogy (SMTP, POP, IMAP) are all like this, with the caveat
that IMAP tags commands and responses (so the second word, not the
first, is the command). FTP is almost there, apart from its secondary
data channel. MUDs are definitely right there. And when I started
putting together some networking facilities at work, I naturally
gravitated to this kind of system. Even when it's a purely internal
protocol, I like being able to just telnet/netcat to the service and
operate everything manually. To date, I think I've implemented five or
six such protocols within the suite at work, with only a couple of
systems done differently (one of them uses a PHP client, for
hysterical raisins, so it's done over HTTP).

Plus, it's great to be able to break out the MUD client at work
without getting in trouble for playing games on company time :)

ChrisA

[1] http://www.thresholdrpg.com/ if you'd like to join me! You'll be
made very welcome!

[toc] | [prev] | [next] | [standalone]


#50830

From"Eric S. Johansson" <esj@harvee.org>
Date2013-07-18 01:39 -0400
Message-ID<mailman.4825.1374126008.3114.python-list@python.org>
In reply to#50823
On Thu, 18 Jul 2013 00:36:17 -0400, Aseem Bansal <asmbansal2@gmail.com>  
wrote:

> I wanted to do a little project for learning Python. I thought a chat  
> system will be good as it isn't something that I have ever done.
>
> I wanted to know what will I need? I think that would require me these
> 1 learn network/socket programming
> 2 find a free server to host my chat server
> 3 GUI development for clients
>

Not discourage you but this is a "been there, done that" kind of project.  
You could learn more from reading somebody else is code. What hasn't been  
done, and this would be very cool, is a chat program that works  
peer-to-peer with no central server. To do this, you would probably need  
to know about distributed hash tables and methods of piercing address  
translation firewalls (think UDP).

First however, I would suggest taking a look at https://jitsi.org/ and see  
how they do things. You can learn a lot from these people. They are very  
smart.

[toc] | [prev] | [next] | [standalone]


#50831

FromAseem Bansal <asmbansal2@gmail.com>
Date2013-07-17 22:50 -0700
Message-ID<3b8979e5-3b7c-4db2-817c-05c262f65379@googlegroups.com>
In reply to#50830
@Eric S. Johansson

I am a novice who hasn't done any big project in programming. I haven't done anything I can even call a moderate project. I haven't touched web frameworks ever. I have little or no knowledge of network/socket programming. I have never used databases before.

I understand that there are a lot of chat systems out there but I haven't done anything like that before. This is for learning purposes.

Reading someone else's code is good but doing it yourself is better.

Thanks for the suggestion but for now I'll stick to this idea. I am excited about this and I would need that for a hobby project.

[toc] | [prev] | [next] | [standalone]


#50833

FromChris Angelico <rosuav@gmail.com>
Date2013-07-18 16:15 +1000
Message-ID<mailman.4826.1374128133.3114.python-list@python.org>
In reply to#50823
On Thu, Jul 18, 2013 at 2:36 PM, Aseem Bansal <asmbansal2@gmail.com> wrote:
> I wanted to do a little project for learning Python. I thought a chat system will be good as it isn't something that I have ever done.

A good thing to start with. Yes, it's been done before, many times...
but if you think about it, it's the fundamental on which pretty much
everything else is derived. The step from a multi-person chat system
to a multiplayer game is very slight.

> I wanted to know what will I need? I think that would require me these
> 1 learn network/socket programming
> 2 find a free server to host my chat server
> 3 GUI development for clients

Learn network programming, definitely. As an adjunct to that, learn
networking security. For instance, do not think in terms of "the
client will only ever send X"; the server has to be able to cope,
safely, with any stream of bytes coming from the socket. Also, be sure
you understand the difference between bytes (or octets) and Unicode
characters, and know what everything is. Python 3 helps with this.

Finding hosting (I'll use the word "server" here to mean the program,
and will say "hosting" when I mean a computer) is optional though; for
your first tests, use your own computer. You can run the server and a
number of clients all on the same computer, and alt-tab between them;
or, if you have a LAN, you can use that. Then when you want to expand
to the full internet and let your friends in on this, you can still
host it on your home internet connection, though you may need to
choose carefully which port you use (some home connections prevent
incoming port 25 and 80 traffic). You won't need to worry about
hosting until (a) you need it to be up 24x7 and don't want to depend
on your home system, and/or (b) you need more bandwidth/processing
than your home connection will do. Neither will be true of your first
experiments.

GUI development, in my opinion, should be left for Phase Two. Start by
making a very simple system that just works with plain text; later on,
make a fancy graphical interface. Keep the text version working, and
keep them compatible. Trust me, you'll appreciate that text one when
you start debugging - it'll be so easy to see what's going on.

> -I wanted to know whether these are all that I would need or are there more things?
> -Will I need to learn a web framework like Django?

Hmm. I would think not; I'd recommend that a chat system work with TCP
sockets directly, for simplicity and performance. Working with a web
framework implies working with HTTP, and unless you're running this in
a web browser, there's no reason to do that.

> -Will I need to learn something for database management like sql for handling people's account names and password?

Optional. Leave that for Phase Two; to start off with, just let people
type in their own names, and don't worry about authentication
initially (this isn't such a crazy idea - IRC largely works this way).
You can add authentication later.

> Any other advice for me(a novice programmer)?

Get to know as many tools as you can, so that when you're faced with a
problem, you can select the right one for the job. You are not Jeremy
Clarkson, your toolchest is not all hammers :)

In this particular instance, you may find that Python is the best
language for the clients, but not for the server. I've written a
number of chat-server-like systems, most notably MUD clients and
derivatives, and I use Pike for the server. Its biggest advantage
(over Python) is that you can tweak the code while it's running; I've
had Pike servers running for over two years on commodity hardware (and
would still have that uptime today if the UPS hadn't died). Still
trying to claw all that back.. up to 25 weeks so far. Pike and Python
are extremely similar in semantics (even down to having a
nearly-identical internal string representation, as of Python 3.3),
but have distinctly different syntax (Pike looks like C), and their
optimizations are quite different, so performance varies somewhat.
They're both high level languages that let you manipulate functions,
dictionaries, etc, as first-class objects, they're both sufficiently
high performance/efficiency to run something like this on 0.00 load
average (my server's load is more usually from Apache serving PHP
pages than it is from either Pike or Python), and both will serve you
well in this project.

One more tip: Don't be afraid to ask for help! I personally *love*
networking, and will gladly help out with any little problems you run
into; the same, I am sure, will be true of a good number of people on
this list. Networking is a complicated world, and there are a lot of
odd concepts to master; but it's also an immensely fun bunch of
technologies. Why play with just one computer when you can play with
half a dozen!

ChrisA

[toc] | [prev] | [next] | [standalone]


#50872

FromMichael Torrie <torriem@gmail.com>
Date2013-07-18 16:34 -0600
Message-ID<mailman.4847.1374186891.3114.python-list@python.org>
In reply to#50823
On 07/17/2013 11:39 PM, Eric S. Johansson wrote:
> Not discourage you but this is a "been there, done that" kind of project.  
> You could learn more from reading somebody else is code. What hasn't been  
> done, and this would be very cool, is a chat program that works  
> peer-to-peer with no central server. To do this, you would probably need  
> to know about distributed hash tables and methods of piercing address  
> translation firewalls (think UDP).

University CS curricula across the world would disagree with your
assessment of the usefulness of "been there, done that."  Indeed that's
how you learn by doing simple things that have been done many times
before, and discovering the magic of programming and software design.
My uni's CS undergrad degree consists of dozens of contrived projects
that have been done before.  Web crawlers, compilers, expert systems,
chat systems, word counters, etc.

And that's the same way with all fields of endeavor.  Indeed it'd be
silly to tell an enthused hobby builder that building a shed is
pointless as it's been done before.  The shed itself, which would
arguably be useful, is beside the point.

[toc] | [prev] | [next] | [standalone]


#50890

FromJake Angulo <jake.angulo@gmail.com>
Date2013-07-19 17:10 +1000
Message-ID<mailman.4857.1374217859.3114.python-list@python.org>
In reply to#50823

[Multipart message — attachments visible in raw view] — view raw

On Thu, Jul 18, 2013 at 2:36 PM, Aseem Bansal <asmbansal2@gmail.com> wrote:

> I wanted to do a little project for learning Python. I thought a chat
> system will be good as it isn't something that I have ever done.
> ...............
> I wanted to know what will I need?
> 1 learn network/socket programming


I was actually expecting somebody to mention Twisted :)
(or Tornado)

You'll find it easy to use any of these frameworks to power the back-end
chat engine.

[toc] | [prev] | [next] | [standalone]


#50891

FromChris Angelico <rosuav@gmail.com>
Date2013-07-19 17:17 +1000
Message-ID<mailman.4858.1374218264.3114.python-list@python.org>
In reply to#50823
On Fri, Jul 19, 2013 at 5:10 PM, Jake Angulo <jake.angulo@gmail.com> wrote:
> On Thu, Jul 18, 2013 at 2:36 PM, Aseem Bansal <asmbansal2@gmail.com> wrote:
>>
>> I wanted to do a little project for learning Python. I thought a chat
>> system will be good as it isn't something that I have ever done.
>> ...............
>>
>> I wanted to know what will I need?
>> 1 learn network/socket programming
>
>
> I was actually expecting somebody to mention Twisted :)
> (or Tornado)
>
> You'll find it easy to use any of these frameworks to power the back-end
> chat engine.

For something this simple, what do they offer above the basic socket
module? I know that sounds critical but it's not meant to be; I've
never looked into either, as I've grown up using the BSD socket APIs
(in C, 80x86 assembly, C++, REXX, Java, Pike, and Python, on DOS (I
think), OS/2, Windows, and Linux... and possibly other
languages/platforms that I've now forgotten), and am comfortable with
them; but for someone who hasn't been in networking for two decades,
is there a noteworthy ease-of-starting difference? Bear in mind that
use of a framework locks you in to that framework and its ecosystem
(so, most likely, language), while grokking sockets themselves gives
you the freedom to move as required.

ChrisA

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.python


csiph-web