Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

DSTD.Network - New, high level networking library - Async - Open source - Beta

Even though this is part of my DSTD library, I decided to create new topic because this is pretty big library.

This is still in beta: its missing some features, existing features may or may not work correctly. But because this is open source, feel free to modify it.

Features
- NET 2.0 C#
- Open source
- Event driven
- TCP
- High level, use Packet classes to represent data
- Easy to use

If you would like to get some feature, please tell
Example server&client
Protocol definition class.
All subclasses of your protocol can be used as packets (if they derive from Packet abstract class)

Code
internal class MyProtocol : DSTD.Network.Protocol
    {

  public class MyPacket : DSTD.Network.Packet
  {
    public string data;

    public override void CreateFromStream(System.IO.BinaryReader streamReader)
    {
    data = streamReader.ReadString();
    }

    public override void SerializeToStream(System.IO.BinaryWriter streamWriter)
    {
    streamWriter.Write(data);
    }
  }
    }

Server class
Code
internal class MyServer : DSTD.Network.EasyPacketBasedTcpServer<MyProtocol>
    {
  public MyServer() : base(10021)
  {

  }

  protected override void OnConnectionReceived(DSTD.Network.EventDrivenTcpPacketConnection connection)
  {
    MessageBox.Show("Server: Received connection, sending hello world");
    connection.SendPacket(new MyProtocol.MyPacket()
    {
    data = "Hello, World!"
    });
  }

  protected override void OnDisconnection(DSTD.Network.EventDrivenTcpPacketConnection connection)
  {
    MessageBox.Show("Server: Client disconnected");
  }

  protected override void OnPacketReceived(DSTD.Network.EventDrivenTcpPacketConnection connection, DSTD.Network.Packet packet)
  {
    if (packet is MyProtocol.MyPacket)
    {
    MessageBox.Show("Received MyPacket, data: " +
    (packet as MyProtocol.MyPacket).data);
    }
  }
    }

Client (uses TcpClient to connect, I dont think its necessary to create own class for connecting)
Code
System.Net.Sockets.TcpClient client = new System.Net.Sockets.TcpClient();
    client.Connect("localhost", 10021);

    DSTD.Network.EventDrivenTcpPacketConnection connection =
    new DSTD.Network.EventDrivenTcpPacketConnection(
    client.Client, new MyProtocol());
    connection.PacketReceived += connection_PacketReceived;
    connection.EnableReceive();

..

  void connection_PacketReceived(object sender, DSTD.Network.PacketReceivedEventArgs e)
  {
    MessageBox.Show("Client: got packet, sending reply\r\n");

    ((DSTD.Network.EventDrivenTcpPacketConnection) sender).SendPacket(
    new MyProtocol.MyPacket()
    {
    data = "Hello to you too"
    });
    ((DSTD.Network.EventDrivenTcpPacketConnection) sender).Disconnect();
  }

Download
Go to DSTD: https://hackforums.net/showthread.php?tid=2020379 and download & build source code
Hm, let me see if I can get a chat server going, I messed with DragonHunter's NEX, and Omni's "Nexus" networking libraries. :3
I just created a small network sample project (TimeProtocol, TimeServer & TimeFetcherTask).
Its included in source control on codeplex.
(Dec 18, 2011 08:23 AM)Deceptive Wrote:  Hm, let me see if I can get a chat server going, I messed with DragonHunter's NEX, and Omni's "Nexus" networking libraries. :3

Omni's "Nexus"? I think you mean, Aeonhack's "Omni".
(Dec 18, 2011 10:26 AM)Banksу Wrote:  Omni's "Nexus"? I think you mean, Aeonhack's "Omni".

No "Omni" is the whole library, Nexus is the networking part, i rite u wong


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by ahmet1257Mar 10, 2022 09:51 AM 2 228 Mar 10, 2022 09:51 AM
Last Post: benio2
[C#] by LookdadonMar 7, 2022 01:38 PM 7 264 Mar 7, 2022 01:38 PM
Last Post: Lookdadon
[C#] by alizer0Jul 23, 2021 10:47 AM 2 423 Jul 23, 2021 10:47 AM
Last Post: tux1