Skip to main content

JoinChannel

public bool JoinChannel(ChannelType type, string serverAddress, ushort serverPort, string groupName, string inDate, out ErrorInfo errorInfo);

Parameters

ValueTypeDescription
typeChannelType(enum)Channel type to enter. ChannelType.Public(normal) or ChannelType.Guild(guild)
serverAddressstringNetwork address to be connected
serverPortstringServer port to be connected
groupNamestringGroup name of the channel to be connected
inDatestringinDate of the channel to be connected
errorInfostringSuccess/failure information

Description

An attempt is made to enter the chat channel.

  • When the return of the chat channel connection method is 'true,' it only means that the server and socket are connected; it does not mean that the connection to the chat channel is successful.
  • Actual server connection is made after authentication is completed in the chat server, and the success/failure of the user's connection to the general chat channel can be checkedthrough the OnJoinChannel event.
Note on the IP assignment issue in data communication environments
You may experience a connection error, due to the mobile IP address assignment issue, when connecting via a data communication network, such as 3G, LTE, or 5G.
It is a common issue that affects not only BACKND Chat, but also other services such as banking applications.
Instruct users who inquire about not being able to connect to the chat server to follow the steps below to renew their mobile IP addresses and resolve their issues.
  • Unable to connect to the chat server
    Upon the call of JoinChannel, the user should be connected to the channel after an automatic call of the  OnJoinChannel  method; however, the  OnJoinChannel  is not called and there has been no response for a continuous period.

  • Solutions

    • Turn on the airplane mode for 20 - 30 seconds, turn the mode off, and use the device.
    • Use the device after resetting the network
      iOS: Settings > General > Reset > Reset Network Settings
      Android: Settings > General management > Reset > Reset network settings
      * Note that resetting the network will also reset all network settings, including Wi-Fi and Bluetooth.

How to simultaneously enter general and guild channels

When you send requests to connect to the general chat channel and guild chat channel simultaneously, you may fail to connect to both channels or only succeed in connecting to one of them.

In the case of chat channel connection, a series of connection processes is only completed when each channel's connection event(OnJoinChannel/OnJoinGuildChannel) is called.
Therefore, you must complete the connection to a single chat channel first and then send a connection request to the other channel to properly enter both channels.

Example

Simple Example

LitJson.JsonData channel = Backend.Chat.GetGroupChannelList("groupName").Rows()[0];

string address = channel["serverAddress"].ToString();
string serverPort = channel["serverPort"].ToString();
string inDate = channel["inDate"].ToString();
string groupName = "groupName";

ErrorInfo errorInfo;
Backend.Chat.JoinChannel(ChannelType.Public, address , serverPort, groupName, inDate, out errorInfo);

Long Example

string groupName = "Public";
string serverAddress = "";
string alias = "";
string inDate = "";
ushort serverPort = 50000;

// Loads group information
var bro = Backend.Chat.GetGroupChannelList(groupName);

if(bro.IsSuccess())
{
var channels = bro.Rows();
for(int i = 0; i < channels.Count; ++i)
{
// In order, find a channel with less than 190 users
var count = channels[i]["joinedUserCount"].ToString();
var num = int.Parse(count);
if(num >= 190)
{
continue;
}
else
{
// When the channel to enter exists, receives its information and stops searching(break)
serverAddress = channels[i]["serverAddress"].ToString();
alias = channels[i]["alias"].ToString();
inDate = channels[i]["inDate"].ToString();
serverPort = ushort.Parse(channels[i]["serverPort"].ToString());
break;
}
}
Debug.Log(string.Format("address : {0} / groupName : {1} / inDate : {2} / alias : {3}", serverAddress, groupName, inDate, alias));

// Enters the channel with the obtained parameter value
ErrorInfo errorInfo;
Backend.Chat.JoinChannel(ChannelType.Public, serverAddress, 50000, groupName, inDate, out errorInfo);
Debug.Log(errorInfo);
}
else
{
Debug.Log("Error to GetGroupChannelList: " + bro);
}

Return cases

Success cases

When connection between the chat server and the socket is successful
Remember that this is a simple socket connection; the connection to the chat server has not been fulfilled yet.
true
errorInfo : ErrorInfo.Success

Error cases

When connection to the chat server fails
false
errorInfo.Category : ErrorCode.Exception
errorInfo.Reason : "reason"

When the connection between the chat server and the socket fails
false
errorInfo.Category : ErrorCode.SocketOperationError
errorInfo.SocketError : type of socket error that occurred
errorInfo.Reason : "reason"

When an attempt is made for connection while already connected to the general channel
false
errorInfo.Category : ErrorCode.DuplicateConnection
errorInfo.Reason : "Already Online(1)"

Exception Case

When an attempt is made to connect to a chat channel again before the connection to a chat channel is completed
TCP Client is working.

This may occur regardless of whether the target channels are the same or different.
When the above exception continues to occur even when the user is not connected to a channel, it is recommended you call the Initialize chat server connection method.