-
Notifications
You must be signed in to change notification settings - Fork 3
Client
George Michaelides edited this page Mar 25, 2015
·
24 revisions
###Connect / Disconnect to a server
var client = new GemClient( Profile: "GemChat"
ServerName: "GemServer" ,
IP: "127.0.0.1",
Port: 14242);
client.RunAsync(() => new ConnectionApprovalMessage
{
Message = "Incoming client",
Sender = "Example",
Password = "1234"
});
//....
//....
client.Disconnect();
###Specify behavior
OnReceivedServerNotification A server notification is received
HandleErrors An error has occurred
HandleWarnings A warning has occurred
OnConnected Connects
OnConnecting Is initiating handshake
OnDisconnected Disconnects
OnDisconnecting Sends a disconnect message
GemClient.Profile("GemChat")
.OnReceivedServerNotification((notification)=>
{
(notification.Type==NotificationTypes.Message)?
Console.WriteLine("Received message {0}",notification.Message) :
Console.WriteLine("Received unhandled notification")?
});
GemClient.Profile("GemChat")
.OnConnected((client,incomingMessage)=>
{
Console.WriteLine("Connected to {0}",
incomingMessage.SenderConnection);
this.NotifyOthers();
}
//this indicates if the behavior is appended or overrides the previous behaviors
append:true);
###Execute a console command
//The commands' output
GemNetworkDebugger.Echo = Console.WriteLine;
string command = "echo This is a test";
GemClient.SendCommand(commmand);
###Notify the server
GemClient.SendNotification("what's up?");
###Send Messages via Network Package
Simply by decorationg your POCO class with the `NetworkPackage("profile") attribute
More info about network packages
###Lightweight Network Outgoing Messages
INetworkEvent sayEvent;
void SetupNetworkEvent()
{
sayEvent = GemClient.Profile("GemChat")
.CreateNetworkEvent
.HandleWith(this, x => new Action<string,string>(x.Say));
}
public void Say(string name, string message)
{
Console.WriteLine(String.Format("{0} : {1}",name,message);
sayEvent.Send(name,message).
}
###Abstract Network Message Flow