Skip to content

youngmonkeys/ezyfox-server-csharp-client

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
io
 
 
 
 
 
 
net
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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)
    .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