Skip to content
Promote Your Product

Create ImServer Project

Project Introduction

An instant messaging server project based on FreeIM. Designed with business logic and push notifications separated, terminal connections never need to restart when MyImServer is updated. All business code is written in the MyApp project, so restarting the MyApp project won't disconnect terminal sessions.

Each MyImServer manages its corresponding terminal connections. When it receives a redis subscription message, it pushes data to the corresponding terminal connection.

When the business application's imconfig.json has IM enabled, you must also start the IM server project from the IM server cluster addresses.

Install or Upgrade Template

cs
dotnet new install ZhonTai.Template.IMServer

The upgrade template command is the same as the install template command.

Install Specific Version

cs
dotnet new install ZhonTai.Template.IMServer::10.0.0

View Help

cs
dotnet new MyIMServer -h
-p, --port <port>   Port settings
                    Type: int
                    Default: 17010

Uninstall Template

cs
dotnet new uninstall ZhonTai.Template.IMServer

Create IM Server Project

cs
dotnet new MyIMServer -n MyCompanyName.MyIMServer

Customize IM Server Port

cs
dotnet new MyIMServer -n MyCompanyName.MyIMServer -p 17010

appsettings.json

Application configuration file

appsettings.json
{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",
  "Urls": "http://*:17010",
  // IM server configuration
  "ImServerConfig": {
    // Redis client connection string
    "RedisClientConnectionString": "127.0.0.1:6379,password=,poolsize=10,defaultDatabase=6",
    // Server list
    "Servers": [ "127.0.0.1:17010" ],
    // Server
    "Server": "127.0.0.1:17010",
    // Input encoding name
    "InputEncodingName": "GB2312",
    // Output encoding name
    "OutputEncodingName": "GB2312",
    // Health check
    "HealthChecks": {
      // Enable
      "Enable": true,
      // Access path
      "Path": "/health"
    }
  }
}

Note

The redis default database must be consistent with the default database in the business application's imconfig.json, otherwise redis subscription messaging will fail.

launchSettings.json

Development startup configuration file, used to configure startup parameters such as environment variables, startup ports, etc.

launchSettings.json
{
  "$schema": "https://json.schemastore.org/launchsettings.json",
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:17010",
      "sslPort": 0
    }
  },
  "profiles": {
    "ImServer": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "launchUrl": "",
      "applicationUrl": "http://localhost:17010",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}