-
Notifications
You must be signed in to change notification settings - Fork 3
NetworkPackages
George Michaelides edited this page Mar 23, 2015
·
4 revisions
Network packages are used for communication between clients and servers
Annotate your class with the NetworkPackage(string profile) attribute
[NetworkPackage("ExampleGame")]
public class Package
{
public string Player{ get; set; }
public float X { get; set; }
public float Y { get; set; }
}
Client and server package setup is the same. The configuration must start either from GemClient or GemServer.
Create an event that sends the package
var networkPackageEvent = GemClient.Profile("ExampleGame")
.CreateNetworkProtocolEvent<Package>()
.GenerateSendEvent();
Handle an incoming network package
var networkPackageEvent = GemClient.Profile("ExampleGame")
.CreateNetworkProtocolEvent<Package>()
.HandleIncoming(package =>
{
Console.WriteLine("{0} is at X:{1} Y:{2}",
package.Name, package.X, package.Y);
});
Additionally, you can chain HandleIncoming and GenerateSendEvent
var networkPackageEvent = GemClient.Profile("ExampleGame")
.CreateNetworkProtocolEvent<Package>()
.HandleIncoming(package =>
{
Console.WriteLine("{0} is at X:{1} Y:{2}",
package.Name, package.X, package.Y);
})
.GenerateSendEvent();