Skip to content

Commit

Permalink
Merge origin/master
Browse files Browse the repository at this point in the history
  • Loading branch information
BFergerson committed Oct 10, 2015
2 parents a5e36e6 + f139e82 commit 81bf9a4
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Beam is client/server and peer-to-peer compatible networking library. It provide
* Connecting a Client
* Creating Messages
* Sending Messages
* Exchanging Messages
* Queuing Messages
* Broadcasting Messages
* Secure Communication
Expand All @@ -33,12 +34,12 @@ public class ExampleHandler extends BasicHandler
{

public ExampleHandler () {
super (ExampleMessageType.EXAMPLE_MESSAGE);
super (ExampleMessage.EXAMPLE_MESSAGE_ID);
}

@Override
public BeamMessage messageRecieved (Communicator comm, BasicMessage msg) {
System.out.println ("Client sent msg: " + msg.getString ("client_message"));
System.out.println ("Client sent message: " + msg.getString ("client_message"));

//response message
return msg.emptyResponse ().setString ("server_response", "example_reply_message");
Expand Down Expand Up @@ -72,9 +73,10 @@ client.connect ();
```java
public class ExampleMessage extends BasicMessage
{

public final static int EXAMPLE_MESSAGE_ID = 1000;

public ExampleMessage () {
super (ExampleMessageType.EXAMPLE_MESSAGE);
super (EXAMPLE_MESSAGE_ID);
}

public ExampleMessage (BeamMessage message) {
Expand Down Expand Up @@ -102,6 +104,21 @@ exampleMessage = new ExampleMessage (responseMessage);
System.out.println ("Server response: " + exampleMessage.getString ("server_response"));
```

## Exchanging Messages ##

Exchanging a message will send a message and update the original message with the response message given. Useful when the request and response message are the same class as it avoids unnessecary casting like when sending messages.

To create and exchange a BasicMessage to the server from client
```java
ExampleMessage exampleMessage = new ExampleMessage ();
exampleMessage.setString ("client_message", "example_client_message");
if (client.exchangeMessage (exampleMessage)) {
//output server response
System.out.println (exampleMessage.getString ("server_response"));
} else {
System.out.println ("Request timed out!");
}
```

## Queuing Messages ##

Expand Down Expand Up @@ -133,7 +150,7 @@ server.broadcast (exampleMessage);
Client
```java
AES aes = new AES ("password");
BeamMessage aesMessage = new AESBeamMessage (aes, ENCRYPTED_MESSAGE);
BeamMessage aesMessage = new AESBeamMessage (aes, ENCRYPTED_MESSAGE_ID);
aesMessage.set ("secret_variable", "secret_value");

//send and receive response (response is returned decrypted)
Expand All @@ -147,14 +164,14 @@ public class ExampleAESHandler extends AESBeamHandler
{

public ExampleAESHandler (AES aes) {
super (aes, ENCRYPTED_MESSAGE);
super (aes, ENCRYPTED_MESSAGE_ID);
}

@Override
public BeamMessage messageRecieved (Communicator comm, BeamMessage message) {
System.out.println ("Client sent secret: " + message.get ("secret_variable"));

BasicMessage responseMessage = new BasicMessage (ENCRYPTED_MESSAGE);
BasicMessage responseMessage = new BasicMessage (ENCRYPTED_MESSAGE_ID);
responseMessage.setString ("server_response", "server_secret_value");
return responseMessage;
}
Expand All @@ -169,7 +186,7 @@ Client
```java
RSA rsa = new RSA (1024);
RSAConnection rsaConn = client.establishRSAConnection (rsa);
BeamMessage rsaMessage = new RSABeamMessage (rsaConn, ENCRYPTED_MESSAGE);
BeamMessage rsaMessage = new RSABeamMessage (rsaConn, ENCRYPTED_MESSAGE_ID);
rsaMessage.set ("secret_variable", "secret_value");

//send and receive response (response is returned decrypted)
Expand All @@ -183,14 +200,14 @@ public class ExampleRSAHandler extends RSABeamHandler
{

public ExampleRSAHandler (RSA rsa) {
super (ENCRYPTED_MESSAGE);
super (ENCRYPTED_MESSAGE_ID);
}

@Override
public BeamMessage messageRecieved (Communicator comm, BeamMessage message) {
System.out.println ("Client sent secret: " + message.get ("secret_variable"));

BasicMessage responseMessage = new BasicMessage (ENCRYPTED_MESSAGE);
BasicMessage responseMessage = new BasicMessage (ENCRYPTED_MESSAGE_ID);
responseMessage.setString ("server_response", "server_secret_value");
return responseMessage;
}
Expand Down

0 comments on commit 81bf9a4

Please sign in to comment.