By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,458 Members | 1,215 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,458 IT Pros & Developers. It's quick & easy.

network programming

P: n/a
Hello, everyone. I just began school, and they
already assigned us science fair. Since I'm in 8th
grade, I get to do demonstrations for our projects.
I'm probably going to demonstrate Python's networking
capabilities by writing a simple instant messenger
program. I only have a few problems:

1. I know squat about Python network Programming

2. I know nothing about networks

So if any of you know of a good Python Networking
Tutorial or a website with lots of information on
networks and networking, please reply. Thanks!

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Aug 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
If i had started in 8th grade, I'd be Guido MartelliPeters by now!
Anyway, these people claim to have 125 tutorials, it'll take at least a
couple hours to work thru

http://www.awaretek.com/tutorials.html

Aug 21 '05 #2

P: n/a
John Walton wrote:
Hello, everyone. I just began school, and they
already assigned us science fair. Since I'm in 8th
grade, I get to do demonstrations for our projects.
I'm probably going to demonstrate Python's networking
capabilities by writing a simple instant messenger
program. I only have a few problems:

1. I know squat about Python network Programming

2. I know nothing about networks

So if any of you know of a good Python Networking
Tutorial or a website with lots of information on
networks and networking, please reply. Thanks!


I believe the Twisted Matrix library has an IM module written for it and
a tutorial on programming with the library. www.twistedmatrix.com
--
--------------------------
Lucas Raab
lvraab"@"earthlink.net
dotpyFE"@"gmail.com
AIM: Phoenix11890
MSN: dotpyfe "@" gmail.com
IRC: lvraab
ICQ: 324767918
Yahoo: Phoenix11890
Aug 21 '05 #3

P: n/a
On Sun, 21 Aug 2005, John Walton wrote:
Hello, everyone. I just began school, and they already assigned us
science fair. Since I'm in 8th grade, I get to do demonstrations for
our projects. I'm probably going to demonstrate Python's networking
capabilities by writing a simple instant messenger program. I only have
a few problems:

1. I know squat about Python network Programming

2. I know nothing about networks

So if any of you know of a good Python Networking Tutorial or a website
with lots of information on networks and networking, please reply.
Thanks!


There are two sides to this problem. The first is understanding networks
in general, and the specific application protocols you're interested in.
When i say 'understanding networks in general', don't panic - i don't mean
you need to understand everything about how the internet works. In fact,
you don't really need to understand *anything* about how the internet
works, you just need to understand the interfaces it exposes to you. And,
helpfully, that interface is pretty simple: a program can get a connection
to another program, running on a different machine, which amounts ot a
pipe for bytes - both ends can write bytes to the pipe when they feel like
it, and those bytes become available for the other end to read. To open
one of these connections, you need to know the hostname or IP address of
the computer at the far end, and something called a 'port number', which
is basically a way of identifying which program on that machine you want
to talk to; if you want other programs to be able to open connections to
your program, you have to pick a port number and ask the system to give
you any connections that are made to it.

That's pretty much it for the network fundamentals. There is more -
datagram sockets, looking up IP addresses, doing funky things with sockets
- but you can forget about that until you've mastered the basics.

What you do need to understand beyond this, though, is about the
application protocol you're using. The network just gives you a way to
move streams of bytes; in order to actually do anything useful, you need
an agreement between the programs at either end of the connection about
what those bytes mean - that's an application protocol. It's basically a
file format as applied to a network connection instead of a file. Each
application protocol is completely different to every other one (well,
there are a lot of similarities, but they're mostly different), so you'll
need to read up on the one you want to use (or invent your own!) - the
documentation is (almost always) in the form of a document unhelpfully
called a Request For Comments, or RFC; the internet RFCs are published
here:

http://www.rfc-editor.org/

For example, here's the RFC for HTTP version 1.0:

http://www.rfc-editor.org/rfc/rfc1945.txt

RFCs can be pretty heavy going, but they are *the* definitive
specifications, so they're worth reading. Once you're used to them,
they're often easier to read than tutorials, i find.

The second thing is understanding how to do network programming in python.
There's a well-established API in C for network programming - the socket
API - which comes from UNIX; python uses a fairly simple translation of
this as its network API (look in the 'socket' package). The good thing
about this is that this API is well-understood and well-documented. The
bad thing is that it's a bit of a mess (compare and contrast to the API in
Java if you don't believe me). There's detailed documentation for the
socket module here:

http://docs.python.org/lib/module-socket.html

And a very quick tutorial here:

http://www.amk.ca/python/howto/sockets/sockets.html

What it comes down to, though, is that you can do:

import socket
s = socket.socket()
target = ("www.python.org", 80)
s.connect(target)
s.send("GET / HTTP/1.0\r\n\r\n")
reply = ""
while True:
line = s.recv(1000)
if (line != ""):
reply = reply + line
else:
break
s.close()

To create a connection, send some data, and then read some data. In this
case, the code sends a very simple HTTP request.

A slightly easier way to do this is using socket's makefile method - this
gives you a file-like representation of the socket, so you can read and
write data using the familiar file methods.

To accept connections from other machines, do something like this:

ss = socket.socket()
ss.bind(('', 2323))
ss.listen(5)
while True:
s, addr = ss.accept()
s.send("Hello!\r\n")
s.close()

tom

--
Eat + Read + Learn = Word
Aug 22 '05 #4

P: n/a
Tom Anderson wrote:
On Sun, 21 Aug 2005, John Walton wrote:

Hello, everyone. I just began school, and they already assigned us
science fair. Since I'm in 8th grade, I get to do demonstrations for
our projects. I'm probably going to demonstrate Python's networking
capabilities by writing a simple instant messenger program. I only have
a few problems:

1. I know squat about Python network Programming

2. I know nothing about networks

So if any of you know of a good Python Networking Tutorial or a website
with lots of information on networks and networking, please reply.
Thanks!

There are two sides to this problem. The first is understanding networks
in general, and the specific application protocols you're interested in.
When i say 'understanding networks in general', don't panic - i don't mean
you need to understand everything about how the internet works. In fact,
you don't really need to understand *anything* about how the internet
works, you just need to understand the interfaces it exposes to you. And,
helpfully, that interface is pretty simple: a program can get a connection
to another program, running on a different machine, which amounts ot a
pipe for bytes - both ends can write bytes to the pipe when they feel like
it, and those bytes become available for the other end to read. To open
one of these connections, you need to know the hostname or IP address of
the computer at the far end, and something called a 'port number', which
is basically a way of identifying which program on that machine you want
to talk to; if you want other programs to be able to open connections to
your program, you have to pick a port number and ask the system to give
you any connections that are made to it.

That's pretty much it for the network fundamentals. There is more -
datagram sockets, looking up IP addresses, doing funky things with sockets
- but you can forget about that until you've mastered the basics.

I tried to cover those basics as briefly as possible in the tutorial I
mentioned earlier. I'd appreciate your comments on how well I succeeded.
What you do need to understand beyond this, though, is about the
application protocol you're using. The network just gives you a way to
move streams of bytes; in order to actually do anything useful, you need
an agreement between the programs at either end of the connection about
what those bytes mean - that's an application protocol. It's basically a
file format as applied to a network connection instead of a file. Each
application protocol is completely different to every other one (well,
there are a lot of similarities, but they're mostly different), so you'll
need to read up on the one you want to use (or invent your own!) - the
documentation is (almost always) in the form of a document unhelpfully
called a Request For Comments, or RFC; the internet RFCs are published
here:

http://www.rfc-editor.org/

For example, here's the RFC for HTTP version 1.0:

http://www.rfc-editor.org/rfc/rfc1945.txt

RFCs can be pretty heavy going, but they are *the* definitive
specifications, so they're worth reading. Once you're used to them,
they're often easier to read than tutorials, i find.
Not for newbies, though very useful for ensuring high levels of
interoperability (and fascinating when you start to realize that real
products bend the RFCs in various ways).
The second thing is understanding how to do network programming in python.
There's a well-established API in C for network programming - the socket
API - which comes from UNIX; python uses a fairly simple translation of
this as its network API (look in the 'socket' package). The good thing
about this is that this API is well-understood and well-documented. The
bad thing is that it's a bit of a mess (compare and contrast to the API in
Java if you don't believe me). There's detailed documentation for the
socket module here:

http://docs.python.org/lib/module-socket.html

[...]

But then Java's a bit of a mess as a language when compared with Python,
I should say. While I know the language has many adherents, it also
seems to have many programmers who only know enough to follow recipes.
This latter feature is a symptom of the language's popularity, so I
suppose we should expect the same problems in about twenty years when
Python becomes more popular than Java.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/

Aug 22 '05 #5

P: n/a
John Walton wrote:
Hello, everyone. I just began school, and they
already assigned us science fair. Since I'm in 8th
grade, I get to do demonstrations for our projects.
I'm probably going to demonstrate Python's networking
capabilities by writing a simple instant messenger
program. I only have a few problems:

1. I know squat about Python network Programming

2. I know nothing about networks

So if any of you know of a good Python Networking
Tutorial or a website with lots of information on
networks and networking, please reply. Thanks!


Is it the purpose of your project to delve into the
gory details of network programming (or sockets)?
If not, it might be extremely helpful to just not
tire yourself with endless technical debugging sessions,
and instead opt for the use of a high-level communication
mechanism like XML-RPC or Pyro...

--Irmen
Aug 22 '05 #6

P: n/a
On Mon, 22 Aug 2005, Steve Holden wrote:
Tom Anderson wrote:
On Sun, 21 Aug 2005, John Walton wrote:
Hello, everyone. I just began school, and they already assigned us
science fair. Since I'm in 8th grade, I get to do demonstrations for our
projects. I'm probably going to demonstrate Python's networking
capabilities by writing a simple instant messenger program. I only have a
few problems:

1. I know squat about Python network Programming

2. I know nothing about networks

So if any of you know of a good Python Networking Tutorial or a website
with lots of information on networks and networking, please reply. Thanks!
[snipzilla!]

That's pretty much it for the network fundamentals. - but you can
forget about that until you've mastered the basics.


I tried to cover those basics as briefly as possible in the tutorial I
mentioned earlier.


Oops! I missed that.
I'd appreciate your comments on how well I succeeded.
Comment #1: it's a combination of PDF and powerpoint! :) I intended to
have a look at it, but i was in a but of a rush this morning, so i'm
afraid i skipped over it. Right now, i'm using a computer that isn't
capable of reading either format; i'll have a look at the tutorial this
evening (i hope) and get back to you. Not that my opinion is worth much.

Okay, read it. Yes, that covers what we're talking about.
RFCs can be pretty heavy going, but they are *the* definitive
specifications, so they're worth reading. Once you're used to them, they're
often easier to read than tutorials, i find.


Not for newbies, though very useful for ensuring high levels of
interoperability (and fascinating when you start to realize that real
products bend the RFCs in various ways).


Maybe i'm unusual, but i've *always* preferred specs to tutorials for most
learning - specs are definitive, comprehensive and precise, whereas
tutorials are often erroneous, patchy and waffly. Yes, they take more
effort to read, but in the case of the RFCs, not that much, once you have
a very basic level of knowledge - most RFCs are very clearly written.
Perhaps the OP would be better off with tutorials, though - particularly
for the programming side rather than the actual protocols.
The second thing is understanding how to do network programming in python.
There's a well-established API in C for network programming - the socket
API - which comes from UNIX; python uses a fairly simple translation of
this as its network API (look in the 'socket' package). The good thing
about this is that this API is well-understood and well-documented. The bad
thing is that it's a bit of a mess (compare and contrast to the API in Java
if you don't believe me). There's detailed documentation for the socket
module here:

http://docs.python.org/lib/module-socket.html

[...]

But then Java's a bit of a mess as a language when compared with Python,
I should say.


Oh, absolutely - but the socket API is a rare breath of simplicity.
While I know the language has many adherents, it also seems to have many
programmers who only know enough to follow recipes.
True, but let's save that rant for another day.
This latter feature is a symptom of the language's popularity, so I
suppose we should expect the same problems in about twenty years when
Python becomes more popular than Java.


I know. I left comp.lang.java.programmer because it got overrun with
clueless muppets. I don't have anything against newbies, but when a place
is crawling with them to that extent, it's not fun. clp will be like that
one day. i haven't decided if i'll take up Smalltalk or LISP next ...

tom

--
In Milan, [traffic lights] are instructions, in Rome suggestions, and in Naples Christmas decorations. -- James Dowden
Aug 22 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.