Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

ilkinulas/P2P4Android

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#P2P4Android

Peer to peer messaging framework for Android.

  • This is an android library project.
  • Sends and receives text messages.
  • Messages are decoded/encoded with json.
  • Okey Mini multiplayer bluetooth game uses this library.

Bluetooth server start example:

P2PBluetooth p2p = new P2PBluetooth();
p2p.startBluetoothServer(this, new NetworkServiceCallback() {
	
	@Override
	public void onSuccess(NetworkService networkService) {
		//Register a network listener for receiving messages from peers.
		networkService.registerNetworkListener(this);
		
		//You can send messages to peers through networkService.
	}
	
	@Override
	public void onFailure(int reason) {
		/*
		 * For a list of failure reasons see 
		 * https://github.com/ilkinulas/P2P4Android/blob/master/src/com/appsonfire/p2p/NetworkServiceCallback.java
		 */
	}
});

Bluetooth client start example:

P2PBluetooth p2p = new P2PBluetooth();
p2p.startBluetoothClient(this, new NetworkServiceCallback() {
	
	@Override
	public void onSuccess(NetworkService networkService) {
		//Register a network listener for receiving messages from peers.
		networkService.registerNetworkListener(this);
		
		//You can send messages to peers through networkService.
	}
	
	@Override
	public void onFailure(int reason) {
		/*
		 * For a list of failure reasons see 
		 * https://github.com/ilkinulas/P2P4Android/blob/master/src/com/appsonfire/p2p/NetworkServiceCallback.java
		 */
	}
});
  • Create your own messages by extending com.appsonfire.p2p.Message.
  • Messages are converted to JSON string before being sent to peers.
  • Received text messages (in JSON format) are converted to Message instances and delivered to application via NetworkListener interface.
package test;

import com.appsonfire.p2p.Message;

public class ConnectMessage extends Message {
	private String data;

	public ConnectMessage() {
		this.type = MessageType.CONNECT;
	}
	
	public void setData(String data) {
		this.data = data;
	}
	
	public String getData() {
		return this.data;
	}	
}

You should implement NetworkListener and register it to a NetworkService.

package com.appsonfire.p2p;
public interface NetworkListener {
	
	public void messageReceived(Message message);

	public void connectionLost(String endPoint);
	
}

P2P4Android only supports Bluetooth. WIFI support is in progress.

About

P2P Messaging Library For Android

Resources

Stars

28 stars

Watchers

8 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.