Cscmobi.NetCore.Game.Base
1.0.7
dotnet add package Cscmobi.NetCore.Game.Base --version 1.0.7
NuGet\Install-Package Cscmobi.NetCore.Game.Base -Version 1.0.7
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Cscmobi.NetCore.Game.Base" Version="1.0.7" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Cscmobi.NetCore.Game.Base" Version="1.0.7" />
<PackageReference Include="Cscmobi.NetCore.Game.Base" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Cscmobi.NetCore.Game.Base --version 1.0.7
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Cscmobi.NetCore.Game.Base, 1.0.7"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Cscmobi.NetCore.Game.Base@1.0.7
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Cscmobi.NetCore.Game.Base&version=1.0.7
#tool nuget:?package=Cscmobi.NetCore.Game.Base&version=1.0.7
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Server Program
1. Tạo config cho log4net
File log4net.config
<log4net>
<root>
<level value="ALL" />
<appender-ref ref="console" />
</root>
<appender name="console" type="log4net.Appender.ManagedColoredConsoleAppender">
<mapping>
<level value="INFO" />
<forecolor value="Green" />
</mapping>
<mapping>
<level value="WARN" />
<forecolor value="Yellow" />
</mapping>
<mapping>
<level value="ERROR" />
<forecolor value="Red" />
</mapping>
<mapping>
<level value="DEBUG" />
<forecolor value="Blue" />
</mapping>
<layout type="log4net.Layout.PatternLayout">
<conversionpattern value="%date [%thread] %-5level - %message%newline" />
</layout>
</appender>
</log4net>
2. Code cho Server
public class Program
{
static async Task Main(string[] args)
{
// Load configuration
var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));
GameServer server = new GameServer(IPAddress.Parse("127.0.0.1"), 8888);
server.StartAsync();
while (true)
{
Console.WriteLine("Send to Client:");
string message = Console.ReadLine();
GSPacketIn pkg = new GSPacketIn(0);
pkg.WriteString(message);
server.SendToAll(pkg);
}
}
}
/// <summary>
/// Tạo classs GameClient để handle Packet
/// </summary>
public class GameClient : BaseClient
{
public static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public GameClient() : base(2048)
{
AsyncPostSend = true;
}
public override void OnRecvPacket(GSPacketIn pkg)
{
log.Info($"clientId: {pkg.ClientID}");
string message=pkg.ReadString();
log.InfoFormat("Client send: {0}", message);
}
}
/// <summary>
/// Class GameServer kế thừa từ Base
/// </summary>
public class GameServer : BaseServer<GameClient>
{
public static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public GameServer(IPAddress ip, int port) : base(ip, port)
{
}
public override GameClient GetNewClient()
{
return new GameClient();
}
public override void OnClientConnected(GameClient client)
{
}
public override void OnClientDisconnected(GameClient client)
{
log.InfoFormat("Goodbye {0}", client.TcpEndpoint);
}
}
3. Code cho client
public class Program
{
private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
static void Main(string[] args)
{
// Load configuration
var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));
GameClient client = new GameClient("127.0.0.1", 8888);
client.Connect();
while (true)
{
Console.WriteLine("Send message:");
string message = Console.ReadLine();
GSPacketIn pkg = new GSPacketIn(1, "640ec482031209aef9bf2a");
pkg.WriteString(message);
client.SendTCP(pkg);
}
}
}
public class GameClient : BaseConnector
{
private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public GameClient(string ip, int port) : base(ip, port, 2048)
{
}
public override void OnRecvPacket(GSPacketIn pkg)
{
string message = pkg.ReadString();
log.Info($"Server Send: {message}");
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- log4net (>= 2.0.15)
- Microsoft.CSharp (>= 4.7.0)
- Microsoft.Extensions.DependencyInjection (>= 7.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0)
- System.CodeDom (>= 7.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.