Slycex
Slycex
CC#
Created by Slycex on 1/6/2024 in #help
Embed external application in wpf application
Hello, i want embed a game in my wpf application. The game is a turn by turn mmorpg, most people play 8 account (8 client...) It's not easy to navigate with 8 client in windows. ALT+ESC... I want create an application where I can put a navigation bar with tabs at the top and each tab represents 1 client. I search and test many options but none works. I'm sure is possible because one application exist, but i want create mine for share in open source project (app already exist have very bad UI and not open source) Thank you very much !
18 replies
CC#
Created by Slycex on 1/2/2024 in #help
Open existing application in application created in c#
Hello, I want open an Windows application (game) in application created with Winform or Wpf. Is possible ? If is possible, you have documentation or tutorial to do that ? Thanks, Sly.
17 replies
CC#
Created by Slycex on 9/22/2023 in #help
✅ Socket not Listen
Hello when i call OnClientConnected() my console close. Yet, my socket listens well for 100 sec, but the console not wait my client connexion You have an idea ? Thanks you !
class Program
{
static IPAddress ipAddress = IPAddress.Parse("127.0.0.1");
static IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, 5555);
static private Socket listener = new Socket(ipEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

static void Main(string[] args)
{
StartupServer();
OnClientConnected();
}

private static void StartupServer()
{
// Ecoute du serveur
listener.Bind(ipEndPoint);
- listener.Listen(100);
Console.WriteLine("Serveur démarré, en attente du client...");
}

private static async void OnClientConnected()
{
// Connexion du client
- await listener.AcceptAsync();
Console.WriteLine($"Client : \"{ipAddress.MapToIPv4()}\" sur le port : \"{ipEndPoint.Port}\" connecté au serveur.");
}
class Program
{
static IPAddress ipAddress = IPAddress.Parse("127.0.0.1");
static IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, 5555);
static private Socket listener = new Socket(ipEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

static void Main(string[] args)
{
StartupServer();
OnClientConnected();
}

private static void StartupServer()
{
// Ecoute du serveur
listener.Bind(ipEndPoint);
- listener.Listen(100);
Console.WriteLine("Serveur démarré, en attente du client...");
}

private static async void OnClientConnected()
{
// Connexion du client
- await listener.AcceptAsync();
Console.WriteLine($"Client : \"{ipAddress.MapToIPv4()}\" sur le port : \"{ipEndPoint.Port}\" connecté au serveur.");
}
11 replies
CC#
Created by Slycex on 9/22/2023 in #help
✅ Unable to read beyond the end of the stream.
Hello, i have error : Unable to read beyond the end of the stream. at line "short hiheader = reader.ReadInt16();" do you know for what ? thanks
IPAddress ipAddress = IPAddress.Parse("127.0.0.1");
IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, 5555);

using Socket listener = new Socket(ipEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

listener.Bind(ipEndPoint);
listener.Listen(100);
Console.WriteLine("Serveur démarré, en attente du client...");

var handler = await listener.AcceptAsync(); // Connexion du client
Console.WriteLine($"Client : \"{ipAddress.MapToIPv4()}\" sur le port : \"{ipEndPoint.Port}\" connecté au serveur.");


MemoryStream memoryStream = new MemoryStream();
var buffer = new byte[1024];

while (true)
{
int byteReceived = await handler.ReceiveAsync(buffer, SocketFlags.None);

if(byteReceived > 0)
{
memoryStream.Write(buffer, 0, byteReceived);
}
else
{
break;
}

BinaryReader reader = new BinaryReader(memoryStream);

- short hiheader = reader.ReadInt16(); // HiHeader (2octets) = packetId (8bits) + lenType (6bits)
short packetId = ((short)(hiheader >> 2));
short lenType = ((short)(hiheader & 3));
IPAddress ipAddress = IPAddress.Parse("127.0.0.1");
IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, 5555);

using Socket listener = new Socket(ipEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

listener.Bind(ipEndPoint);
listener.Listen(100);
Console.WriteLine("Serveur démarré, en attente du client...");

var handler = await listener.AcceptAsync(); // Connexion du client
Console.WriteLine($"Client : \"{ipAddress.MapToIPv4()}\" sur le port : \"{ipEndPoint.Port}\" connecté au serveur.");


MemoryStream memoryStream = new MemoryStream();
var buffer = new byte[1024];

while (true)
{
int byteReceived = await handler.ReceiveAsync(buffer, SocketFlags.None);

if(byteReceived > 0)
{
memoryStream.Write(buffer, 0, byteReceived);
}
else
{
break;
}

BinaryReader reader = new BinaryReader(memoryStream);

- short hiheader = reader.ReadInt16(); // HiHeader (2octets) = packetId (8bits) + lenType (6bits)
short packetId = ((short)(hiheader >> 2));
short lenType = ((short)(hiheader & 3));
5 replies
CC#
Created by Slycex on 9/21/2023 in #help
✅ Dynamic Buffer
Hello ! I want create a dynamic buffer and i didnt know how to proced. I want Receive bytes of my client, and stock only the bytes receive. Actualy use :
byte buffer = new byte[1024]
var received = await handler.ReceiveAsync(buffer, SocketFlags.None)
byte buffer = new byte[1024]
var received = await handler.ReceiveAsync(buffer, SocketFlags.None)
problem is i use lot of memory unnecessarily if receive little packet Thanks for your help, Slycex. PS : sorry for my english :S
23 replies