Skip to content

youngmonkeys/ezyfox-server-csharp-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

e38302a · Feb 4, 2024
Jan 20, 2023
Jul 8, 2023
Oct 13, 2018
Jul 8, 2023
Nov 5, 2023
Jul 8, 2023
Oct 1, 2021
Jul 8, 2023
Aug 27, 2019
Feb 20, 2020
Jan 20, 2023
Apr 14, 2022
Jul 8, 2023
Dec 15, 2022
Aug 3, 2019
Aug 31, 2021
Oct 14, 2018
Aug 3, 2019
Jul 8, 2023
Nov 8, 2023
Jul 17, 2021
Feb 4, 2024
Apr 14, 2022
Aug 31, 2023
Oct 17, 2023
Apr 7, 2021
Jul 9, 2023
Oct 13, 2018
Aug 3, 2019
Oct 17, 2023
Oct 17, 2023
Apr 7, 2021
Nov 25, 2023
Oct 17, 2023

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 ✨