Skip to content

youngmonkeys/ezyfox-server-csharp-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ezyfox-server-csharp-client

csharp, unity client for ezyfox server

Synopsis

csharp, unity client for ezyfox server

For Unity

Please move to the unity-client branch.

Documentation

https://youngmonkeys.org/ezyfox-csharp-client-sdk/

Code Example

1. Import

using com.tvd12.ezyfoxserver.client.config;
using com.tvd12.ezyfoxserver.client;
using com.tvd12.ezyfoxserver.client.constant;
using com.tvd12.ezyfoxserver.client.entity;
using com.tvd12.ezyfoxserver.client.factory;
using com.tvd12.ezyfoxserver.client.handler;
using com.tvd12.ezyfoxserver.client.evt;
using com.tvd12.ezyfoxserver.client.request;

2. Create a TCP Client

var config = EzyClientConfig.builder()
    .clientName(ZONE_NAME)
    // .enableSSL()
    // .enableDebug()
    .build();
socketClient = new EzyUTClient(config);
EzyClients.getInstance().addClient(socketClient);

3. Setup client

setup.addEventHandler(EzyEventType.CONNECTION_SUCCESS, new EzyConnectionSuccessHandler());
setup.addEventHandler(EzyEventType.CONNECTION_FAILURE, new EzyConnectionFailureHandler());
setup.addEventHandler(EzyEventType.DISCONNECTION, new DisconnectionHandler());
setup.addDataHandler(EzyCommand.HANDSHAKE, new HandshakeHandler());
setup.addDataHandler(EzyCommand.LOGIN, new LoginSuccessHandler());
setup.addDataHandler(EzyCommand.LOGIN_ERROR, new EzyLoginErrorHandler());
setup.addDataHandler(EzyCommand.APP_ACCESS, new AppAccessHandler());
setup.addDataHandler(EzyCommand.UDP_HANDSHAKE, new UdpHandshakeHandler());

4. Setup app

var appSetup = setup.setupApp(APP_NAME);
appSetup.addDataHandler("reconnect", new ReconnectResponseHandler());
appSetup.addDataHandler("getGameId", new GetGameIdResponseHandler());
appSetup.addDataHandler("startGame", new StartGameResponseHandler());

5. Connect to server

socketClient.connect("127.0.0.1", 3005);

6. Handle socket's events on main thread

For one client:

while (true)
{
	Thread.Sleep(3);
	client.processEvents();
}

For multiple clients:

IList<EzyClient> cachedClients = new List<EzyClient>();
while(true) 
{
    Thread.Sleep(3);
    clients.getClients(cachedClients);
    foreach (EzyClient client in cachedClients)
    {
        client.processEvents();
    }
}

Used By

  1. Defi Warrior
  2. EzySmashers
  3. ...
  4. Your awesome project ✨