Firstly, considerable credit must go to Kip, as the event driven TCP is primarily based off his UDF.
Objective of this UDF:
To provide dead-easy functionality for internet/LAN applications that do not need/want a server. In simpler terms, an easy to use P2P engine.
If your confused, a simplistic way of thinking of this would be to think of it as a re-write of kip's TCP UDF, that allows a 'client and server in the same script'. =]
PLEASE READ THE ENTIRE POST IF YOU WANT TO UNDERSTAND HOW TO USE THIS.
How it works:
##################
When you start the UDF, it will start listening and accepting incoming connections. The UDF will, in the backround, continue to manage all your connections and initiate any new ones should you use the _P2P_Connect( IP) function. It will also manage the recieving and sending of data.
As a P2P node should, it will route data destined for others, and it will also maintain a healthy number of connections (the number which you define when you start the node).
This entire system is event driven, so you will register your functions with the UDF and the function will get called when the corresponding event happens. See the comments in the UDF for more information.
This works in the same way as Kip's TCP UDF.
Structure:
##################
The first thing you must do is start the Node:
_P2P_Start_Node( Node Identifier, Port, Max peers, Bootstrap mode, Bootstrap max, local/global, IP)
All the Parameters are pretty self expanatory. The Node identifier is the name of your computer in the network. It must not change across sessions and it must be unique. It is used to identify you in your network.
Bootstrapping means autoconnecting. if Bootstrap mode is 1, It will autoconnect you to others until you reach your Bootstrap Max.
Local/Global - Put 0 if working on a LAN, 1 if over internet.
IP - (Optional). You shouldn't need to change this. It is the IP of the listening port.
The second thing is declare your functions. This tells the UDF which functions to call when something happens. EG:
_P2P_Register_Event($P2P_RECEIVE, "my_recieve_function")
So, this will call the function my_recieve_function when data from a peer is recieved. See the comments at the beginning of the UDF for a complete list of Event values, and the parameters for your functions.
Then fire away!
_P2P_Send( $socket, "MY DATA!!)
_P2P_Connect( "127.0.0.1")
_P2P_Broadcast( "My data")
When your done,
_P2P_Stop_Node()
EDIT:
There is also a very powerful system I forgot to mention earlier called long range message routing. Basically, it allows you to send messages in your P2P network to peers you are not connected to, but someone else in the network is. Consider this:
P1 is connected to P2 and P3. P4 is connect to P3. P1 wants to send message to P4.
You would use my function _P2P_Send_Message. It will route your message from P1 -> P3 -> P4 automatically. The speed of processing for three nodes will be approx. 90ms, so it will be relatively fast.
UDF:
P2PTCP.au3 36.21K
870 downloadsEXAMPLE:
P2Ptest.au3 1.38K
794 downloadsNot the best example but it will do. Notice that the UDF by default prints to console.
Hope you enjoy it!
Hypoz.
Edited by hyperzap, 16 November 2010 - 11:47 PM.







