c# messenger, send commands over network, protocol?

multiple client server chat program in c#
c# socket async/await
networking in c#
c# chat application over internet
c# server
c# socket receiveasync example
asynchronous socket programming in c#
client server windows application in c#

I'm making a c# messenger application just for fun, but I wanna do it good. I want the possibility to send commands like a chat message, kick comand etc, but i dont know a good way to control it.

I could send an object over the networkstream, or I could send a string like: stream.write("command##");

maybe you know another way to fix this things, but I'm in stackoverflow atm. Thanks.


It seems like you already have a handle on building your sockets from the use of Stream.Write() in your question.

You might want to try something that builds a byte array with a message type, and some sort of checksum. For example:

        string message = "this is your message";
        byte packetType = 1;
        byte checksum = 0;

        // calculate a simple checksum
        foreach (char c in message)
        {
            checksum ^= (byte)c;
        }


        // type, message, checksum into buffer
        // (uses list instead of playing with arrays for expeditious example code)
        List<byte> buffer = new List<byte>();
        buffer.Add(packetType);
        buffer.AddRange(ASCIIEncoding.UTF8.GetBytes(message));
        buffer.Add(checksum);

        // write out to the socket
        CommStream.Write(buffer.ToArray(), 0, buffer.Count);

once you feel adventerous to go beyond sending simple strings, you can attempt serializing objects to byte arrays using the runtime namespace:

    using System.IO;
    using System.Runtime.Serialization.Formatters.Binary;

    public class Message : ISerializable
    {
        DateTime timestamp;
        byte type;
        string message;
    }

    public byte[] BuildBuffer(Message input)
    {
        // Serialize the message
        Stream s = new MemoryStream();
        BinaryFormatter binaryFormatter = new BinaryFormatter();
        binaryFormatter.Serialize(s, input);
        buffer = s.ToArray();

        return buffer;
    }

    public Message BuildMessage(byte[] input)
    {
        Stream s = new MemoryStream(input);
        s.Position = 0;

        BinaryFormatter binaryFormatter = new BinaryFormatter();
        return (Message)binaryFormatter.Deserialize(s);
    }

TCP/IP Chat Application Using C#, This is a LAN chat application with TCP/IP socket programming technology in C#. To be precise, I have created a command client and a command server, For sending and receiving data to and from the network you should call In a connection-oriented socket, the TCP protocol is used to establish a  All the examples i found are sending only text/string data over the network. I figure out how to send different types of objects (ArrayLists etc). I'm now trying to find out how to process commands sent from the client on the server.


Just have some sort of control character (like ) ... when the server sees that character, it starts to record until it receives a space character. Once it hits the space, it looks at the string and compares it against a list of available commands (\kick, etc.).

That's but one technique to tackle this problem. Honestly, if you're doing it for fun, implement it whatever way is the most fun to code :-)

Asynchronous Client Socket Example, NET Framework program creates a client that connects to a server, using an asynchronous socket. The application sends a string to the server and then displays the string returned by the server on the console. C# Copy. using System; using System.Net; using System.Net. Stream, ProtocolType. 7,11611 gold badge2121 silver badges3939 bronze badges. add a comment |. 1. Basically, you'll want to do it the same way you would in any other language. You'll open a network connection of one flavor or another (raw TCP or UDP, or a higher level protocol like HTTP) with one side acting as a server and the other acting as a client.


If you want to turn your "for fun" project into a "professional development" project (as in, develop your skills, not professional-quality) try WCF. It will handle the entire messaging architecture for you, and let you focus on your functionality. Plus, WCF looks good on the resume.

How to C# Socket programming, Net.Sockets . A Socket is an End-Point of To and From (Bidirectional) Socket Program and C# Client Socket Program using TCP/IP Communication Protocol. it will establish a connection to the C# Server program and send request to the​  When you start writing more and more code like this, you'll end up writing dedicated methods for sending integers, strings (the protocol above is basically just sending a length-prefix 'Pascal' string), and other primitives; similarly for the server. Server Side. on the client, we provide a method to 'send' a string.


How to send Data via UDP packets in C# Tutorial, How to send Data via UDP packets in C# Tutorial. HazardEdit. Loading #​Messenger Duration: 5:51 Posted: Dec 28, 2015 vote 1 vote 2 vote 3 vote 4 vote 5. Please Sign up or sign in to vote. 4.89 (33 votes) 26 Jul 2012 CPOL. Instant messaging in C# .NET using TCP protocol with SSL encryption and authentication. Download demo project - 17.1 KB.


C# Tutorial - TCP/IP Client Server, Network Programming in C#, TcpClient using visual studio c# tutorial Could you teach me Duration: 10:12 Posted: Jan 27, 2017 This is a LAN chat application with TCP/IP socket programming technology in C#. This application is a multi thread network application and works in a non-blocking way. Public and private chat is also implemented in this code. Download source files - 345 Kb. Download demo - 298 Kb.


C# Tutorial 78: How to make a Chat Program in C# Part-1/4, How to create simple chat messenger in c#.net . Linux Command Line Tutorials ➡️ http Duration: 10:16 Posted: Jun 12, 2013 GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together. Sign up rconsharp is a Valve RCON protocol implementation for .NET written in C#