473,663 Members | 2,694 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Establishing a p2p connection in python

gs
Hi!

This is my first time posting to a newsgroup so please be gentle to me
:)

Introduction to my problem:

I'm studying at the university and a lot of friends and I use MSN to
communicate. The problem is that MSN file sending/receiving
capabilities are terribly slow and has no resume option. We're also on
different subnets and can not access eachoters computers through smb
shares, nor can we have local ftp-servers.

My programming background:

I've been taking a few classes in JAVA, enough to get familiar with
sockets, threads and the most common sorting algortithms and
datastructures (binary trees, stacks etc). I'm also very comfortable
programming PHP on a webdeveloper basis.
I recently started out with Python and i immediatly fell in love with
it, and now I want to "master" it! :) Alas, my problem is also of
educational nature.

Setup:
We're about 30 friends who want the ability to share files.
We're spread out on about 3 different translated external IPs.
I have access to a public IP that has the ability to run python (but
not enough bandwith nor space to host an FTP).
I have limited programming experience.

Proposed solution:
I thought that one approach could be to write a small server for my
public server with the sole purpose of keeping track of connected
users and establishing p2p connections on demand.

Problems:
1) I've written a threaded server that stores information about
connected servers in a "container class". This class holds information
about username, a unique ID, the connecting adress and the actual
socket. I have not been able to find any information online on how i
could go about to connect two sockets. It would seem like the socket
is already "occupied" since it is connected to the server. Could one
duplicate, or otherwise get a dedicated socket for sending binary
data, to one connected socket from another? A few pointers and/or tips
would be greatly appreciated!

2) I've also failed to find python specific information on how abouts
one would do file resuming. I would think that you, somehow, use
md5-checksums to check file status and somehow skip the first part of
the datastream. Also, pointers and maybe an explanation in (short)
pseudo-code would be much appreciated.

3) Is this too big of a project for a novice programmer such as
myself? I do want to go through with this since it's a genuine
problem, but i do not know if i'm ready. I'm not a "quitter" per say,
but i'm afraid doing something TOO advanced in the beginning might be
overwhelming :)

Thanks for reading,
gs
Jul 18 '05 #1
8 3516
gs <gs******@gmail .com> wrote:
...
We're about 30 friends who want the ability to share files.


You could look into BitTorrent, a popular p2p program which, I believe,
is implemented in Python. Maybe, if not usable as-is, it might be made
to fit your needs with some minor modifications.. .?
Alex
Jul 18 '05 #2
gs wrote:
Hi!

This is my first time posting to a newsgroup so please be gentle to me
:)
Welcome. You have little to fear from this crowd.
Introduction to my problem:
<snip>
I think that your problem can be solved with Twisted. That is _a_
solution. Not the only, maybe not the best for everything you're
wanting to do (which it seems that learning a lot is important to you),
but _a_ solution. It's got a bit of a learning curve to wrap your head
around how everything fits together, but it's a powerful framework.
I've used it less than I plan to, but I've got some interest in how it
works.
Problems:
1) I've written a threaded server that stores information about
connected servers in a "container class". This class holds information
about username, a unique ID, the connecting adress and the actual
socket. I have not been able to find any information online on how i
could go about to connect two sockets. It would seem like the socket
is already "occupied" since it is connected to the server. Could one
duplicate, or otherwise get a dedicated socket for sending binary
data, to one connected socket from another? A few pointers and/or tips
would be greatly appreciated!

Are you talking about your server binding two different ports? If you
are using the Python standard SocketServer, you should be able to just
spin off a thread for each server you start and tell it to
serve_forever() (or what have you). If you're using Twisted, I think
all you would need to do is factory.listenT CP(<port number>, <factory>),
then reactor.run(). I'll leave getting data between the different ports
you've bound as an exercise for the reader.
2) I've also failed to find python specific information on how abouts
one would do file resuming. I would think that you, somehow, use
md5-checksums to check file status and somehow skip the first part of
the datastream. Also, pointers and maybe an explanation in (short)
pseudo-code would be much appreciated.

Can't help you here, sorry.
3) Is this too big of a project for a novice programmer such as
myself? I do want to go through with this since it's a genuine
problem, but i do not know if i'm ready. I'm not a "quitter" per say,
but i'm afraid doing something TOO advanced in the beginning might be
overwhelming :)

I don't think this is too big at all. But I do think you'll want to
break it down a little bit and set smaller goals for yourself. Try to
first get the smallest fairly usable thing working. Then you can start
adding functionality from there.
Thanks for reading,
gs

HTH,
Jeremy Jones
Jul 18 '05 #3
quoth the gs:
Hi!

This is my first time posting to a newsgroup so please be gentle to me

:)

Introduction to my problem:

I'm studying at the university and a lot of friends and I use MSN to
communicate. The problem is that MSN file sending/receiving
capabilities are terribly slow and has no resume option. We're also on
different subnets and can not access eachoters computers through smb
shares, nor can we have local ftp-servers.

My programming background:

I've been taking a few classes in JAVA, enough to get familiar with
sockets, threads and the most common sorting algortithms and
datastructures (binary trees, stacks etc). I'm also very comfortable
programming PHP on a webdeveloper basis.
I recently started out with Python and i immediatly fell in love with
it, and now I want to "master" it! :) Alas, my problem is also of
educational nature.

Setup:
We're about 30 friends who want the ability to share files.
We're spread out on about 3 different translated external IPs.
I have access to a public IP that has the ability to run python (but
not enough bandwith nor space to host an FTP).
I have limited programming experience.

Proposed solution:
I thought that one approach could be to write a small server for my
public server with the sole purpose of keeping track of connected
users and establishing p2p connections on demand.

Problems:
1) I've written a threaded server that stores information about
connected servers in a "container class". This class holds information
about username, a unique ID, the connecting adress and the actual
socket. I have not been able to find any information online on how i
could go about to connect two sockets. It would seem like the socket
is already "occupied" since it is connected to the server. Could one
duplicate, or otherwise get a dedicated socket for sending binary
data, to one connected socket from another? A few pointers and/or tips
would be greatly appreciated!

2) I've also failed to find python specific information on how abouts
one would do file resuming. I would think that you, somehow, use
md5-checksums to check file status and somehow skip the first part of
the datastream. Also, pointers and maybe an explanation in (short)
pseudo-code would be much appreciated.

3) Is this too big of a project for a novice programmer such as
myself? I do want to go through with this since it's a genuine
problem, but i do not know if i'm ready. I'm not a "quitter" per say,
but i'm afraid doing something TOO advanced in the beginning might be
overwhelming :)

Thanks for reading,
gs


I can suggest taking a look at nicotine, which is a full fledged p2p app
written in python. I'm not saying it's your solution, but you may get some
ideas about how to implement what you want by reading the source code, as it
does support file resuming.

-d

--
Part of the problem since 1976
http://badcomputer.no-ip.com
Get my public key from
http://keyserver.linux.it/pks/lookup...earch=bulliver
"...the number of UNIX installations has grown to 10, with more expected..."
- Dennis Ritchie and Ken Thompson, June 1972

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQBBZrDxOrz WcOwL7mwRAu9zAJ 996iG8jAuNzdnVY CFTlc6TrAc/GgCffScs
FZK6DINDLa4YmWA Hrc2OIo4=
=tR8D
-----END PGP SIGNATURE-----

Jul 18 '05 #4
>>>>> "gs" == gs <gs******@gmail .com> writes:

gs> Proposed solution: I thought that one approach could be to
gs> write a small server for my public server with the sole
gs> purpose of keeping track of connected users and establishing
gs> p2p connections on demand.

One lightweight approach (assuming that a web server is available)
would be to put up a cgi script that adds the ip:port information to
onlineusers.txt . Then the clients can just use urllib to notify the
script when they become online, and also get the list of connected
clients by just retrieving onlineusers.txt . Of course onlineusers.txt
could contain the lists of shared files for each client as well...

If you use unique user ids, you can keep the file from growing up too
much. If not, you could clean up dead clients by trying to connect all
the specified addresses.

gs> 1) I've written a threaded server that stores information
gs> about connected servers in a "container class". This class
gs> holds information about username, a unique ID, the connecting
gs> adress and the actual socket. I have not been able to find any
gs> information online on how i could go about to connect two
gs> sockets. It would seem like the socket is already "occupied"
gs> since it is connected to the server. Could one duplicate, or
gs> otherwise get a dedicated socket for sending binary data, to
gs> one connected socket from another? A few pointers and/or tips
gs> would be greatly appreciated!

If you went on to "connect" the two sockets, you would just
instantiate a thread that forwards the data, and would use more server
bandwidth than an FTP server would have used.

The idea in p2p is to make clients connect to each other. The task of
the server is to tell the clients about other clients so they can
connect to each other.
gs> 2) I've also failed to find python specific information on how
gs> abouts one would do file resuming. I would think that you,
gs> somehow, use md5-checksums to check file status and somehow
gs> skip the first part of the datastream. Also, pointers and
gs> maybe an explanation in (short) pseudo-code would be much
gs> appreciated.

It's trivial since you are going to implement a custom protocol
anyway. Make the "get file" command that you pass to the file provider
such that in addition to the file name you pass the starting offset
within the file.
gs> 3) Is this too big of a project for a novice programmer such
gs> as myself? I do want to go through with this since it's a
gs> genuine problem, but i do not know if i'm ready. I'm not a
gs> "quitter" per say, but i'm afraid doing something TOO advanced
gs> in the beginning might be overwhelming :)

No, it's a great first project. Go ahead, I believe you will find it
surprisingly easy, educational and something for which Python is a
perfect fit.

It'll be a fun project to expand as well, to provide chunked file
transfer etc. You could also explore the alternative of making it a
bunch of wrapper scripts that just invoke bittorrent...

--
Ville Vainio http://tinyurl.com/2prnb
Jul 18 '05 #5
gs
al*****@yahoo.c om (Alex Martelli) wrote in message news:<1glc4eg.z vju3nsu0g6N%al* ****@yahoo.com> ...
gs <gs******@gmail .com> wrote:
...
We're about 30 friends who want the ability to share files.


You could look into BitTorrent, a popular p2p program which, I believe,
is implemented in Python. Maybe, if not usable as-is, it might be made
to fit your needs with some minor modifications.. .?
Alex


Ok, that sounds very interesting, Alex. BitTorrent seems to be able to
handle my needs at the moment, althoug i'd eventually want to write
something myself :) Thanks for the pointer!

Off to read up on this and try to persuade my isp to let me add
..torrent apptypes :)

sincerely,
gs
Jul 18 '05 #6
>>>>> "gs" == gs <gs******@gmail .com> writes:

gs> Off to read up on this and try to persuade my isp to let me
gs> add .torrent apptypes :)

What does your ISP have to do with this? .torrents are just normal
files.

--
Ville Vainio http://tinyurl.com/2prnb
Jul 18 '05 #7
gs
Ville Vainio <vi***@spammers .com> wrote in message news:<du******* ******@lehtori. cc.tut.fi>...
>> "gs" == gs <gs******@gmail .com> writes:

gs> Proposed solution: I thought that one approach could be to
gs> write a small server for my public server with the sole
gs> purpose of keeping track of connected users and establishing
gs> p2p connections on demand.

One lightweight approach (assuming that a web server is available)
would be to put up a cgi script that adds the ip:port information to
onlineusers.txt . Then the clients can just use urllib to notify the
script when they become online, and also get the list of connected
clients by just retrieving onlineusers.txt . Of course onlineusers.txt
could contain the lists of shared files for each client as well...

If you use unique user ids, you can keep the file from growing up too
much. If not, you could clean up dead clients by trying to connect all
the specified addresses.

gs> 1) I've written a threaded server that stores information
gs> about connected servers in a "container class". This class
gs> h


olds information about username, a unique ID, the connecting gs> adress and the actual socket. I have not been able to find any
gs> information online on how i could go about to connect two
gs> sockets. It would seem like the socket is already "occupied"
gs> since it is connected to the server. Could one duplicate, or
gs> otherwise get a dedicated socket for sending binary data, to
gs> one connected socket from another? A few pointers and/or tips
gs> would be greatly appreciated!

If you went on to "connect" the two sockets, you would just
instantiate a thread that forwards the data, and would use more server
bandwidth than an FTP server would have used.

The idea in p2p is to make clients connect to each other. The task of
the server is to tell the clients about other clients so they can
connect to each other.
gs> 2) I've also failed to find python specific information on how
gs> abouts one would do file resuming. I would think that you,
gs> somehow, use md5-checksums to check file status and somehow
gs> skip the first part of the datastream. Also, pointers and
gs> maybe an explanation in (short) pseudo-code would be much
gs> appreciated.

It's trivial since you are going to implement a custom protocol
anyway. Make the "get file" command that you pass to the file provider
such that in addition to the file name you pass the starting offset
within the file.
gs> 3) Is this too big of a project for a novice programmer such
gs> as myself? I do want to go through with this since it's a
gs> genuine problem, but i do not know if i'm ready. I'm not a
gs> "quitter" per say, but i'm afraid doing something TOO advanced
gs> in the beginning might be overwhelming :)

No, it's a great first project. Go ahead, I believe you will find it
surprisingly easy, educational and something for which Python is a
perfect fit.

It'll be a fun project to expand as well, to provide chunked file
transfer etc. You could also explore the alternative of making it a
bunch of wrapper scripts that just invoke bittorrent...


Thanks all of you for the nice feedback. I'm spending all of my
sparetime just reading up on all technlogies and suggestions! :)

cheers,
gs
Jul 18 '05 #8
gs******@gmail. com (gs) wrote in message news:<a5******* *************** ****@posting.go ogle.com>...
Hi!

This is my first time posting to a newsgroup so please be gentle to me
:)

Introduction to my problem:

I'm studying at the university and a lot of friends and I use MSN to
communicate. The problem is that MSN file sending/receiving
capabilities are terribly slow and has no resume option. We're also on
different subnets and can not access eachoters computers through smb
shares, nor can we have local ftp-servers.

<snip>

You might look into the Waste p2p software. It is a p2p program that
uses RSA encryption and requires manual addition of nodes, I believe.
So you can use it to create a private p2p network. It might work for
you, or at least give you some ideas in terms of security features and
such.
Jul 18 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1491
by: ajikoe | last post by:
Hello all, I have one computer and 1 server. I have login and password. The only way I can connect to server is using SSH protocol. I usually use Winscp3 to connect to the server (by providing login and password). Now I would like to connect to the server directly using python code. How can I establish connection ? Can I run something in the server and take the result back?
3
1704
by: gaffar | last post by:
Sir, Using ADOX I am developing an application in vb.net and the backend database is ms-access. i have created ms-access databse and tables and assigned primary keys to the tables through the vb.net application(code is below) by using ADOX. Now my problem is i want delete one record from master table, that deleted record automatically deleted from child tables. so, i want the code how to establish relation ships between the tables and...
3
3612
by: thom | last post by:
Using Vs2005 sqlServer 2005 When i try to connect i get this error: An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) Connection string:
0
1442
by: Tor Inge Rislaa | last post by:
Just for testing deployment of an asp.net application to the remote server I have crated an application based on the StarterKit application in Visual Studio 2005. When trying to run the application from my browser I get the error message below.
0
1220
by: fatma82 | last post by:
hii anybody can help me. i am trying to connect SQL Server 2000 with ASP.NET 2.0 Web Service.I have changed iss to Windows auth. but it didnt work. System.Data.SqlClient.SqlException: An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes...
0
1770
by: Mangabasi | last post by:
Howdy, I would like to use the Synthesis Toolkit for a demo. I downloaded the STK from http://ccrma.stanford.edu/software/stk/index.html. It seems very powerful and user friendly. There are bindings for socket connections and TCL gui examples. I would like to get one of the demo samples work with Python/wxPython. I am including the TCL code for the drums demo (this was the shortest one). Has anybody converted this to wxPython? ...
4
5363
by: weird0 | last post by:
I have written a webservice locally, and upon consuming or testing it in the explorer there is a problem. It throws the following exception: System.Data.SqlClient.SqlException: An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error:...
0
2002
by: aboutjav.com | last post by:
Hi, I need some help. I am getting this error after I complete the asp.net register control and click on the continue button. It crashed when it tries to get it calls this Profile property ((string)(this.GetPropertyValue("Address1")));
0
4615
by: mina | last post by:
My application which is written in vb.net 2005 uses sql server 2005 express as a database, this application is multi-user. So i am used 3 xp machine to install my application i can say machine1,machine2 ,machine3 on which i have install my application. On machine1 i also install SQL Server 2005 express. Then run mu application from machine1 which is locally its work fine. But i am facing problem when i am trying to connect from the...
0
8436
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8345
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8858
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8634
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7371
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6186
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5657
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4349
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2763
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.