Skip to content

luthuanphong/ezyfox-server-csharp-client

 
 

Repository files navigation

ezyfox-server-csharp-client

csharp, unity client for ezyfox server

Synopsis

csharp, unity client for ezyfox server

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)
    .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. hello-csharp
  2. space-shooter

About

csharp client for ezyfox server

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%