Click here to Skip to main content
15,885,164 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to create a many-to-many relationship between users in a table? Pin
Gerry Schmitz16-Sep-22 6:42
mveGerry Schmitz16-Sep-22 6:42 
GeneralRe: How to create a many-to-many relationship between users in a table? Pin
Alex Wright 202216-Sep-22 6:55
Alex Wright 202216-Sep-22 6:55 
GeneralRe: How to create a many-to-many relationship between users in a table? Pin
Eddy Vluggen16-Sep-22 23:59
professionalEddy Vluggen16-Sep-22 23:59 
SuggestionRe: How to create a many-to-many relationship between users in a table? Pin
Richard Deeming19-Sep-22 21:16
mveRichard Deeming19-Sep-22 21:16 
QuestionProgram instalator in C#, Visual Studio Pin
Ismael_199912-Sep-22 5:36
Ismael_199912-Sep-22 5:36 
AnswerRe: Program instalator in C#, Visual Studio Pin
Gerry Schmitz12-Sep-22 6:21
mveGerry Schmitz12-Sep-22 6:21 
AnswerRe: Program instalator in C#, Visual Studio Pin
OG MAYOR MRL25-Sep-22 2:48
OG MAYOR MRL25-Sep-22 2:48 
Questionreading memory stream in byte chunks Pin
mjeeves10-Sep-22 8:41
mjeeves10-Sep-22 8:41 
I want to create a memory stream as follows

[1byte][4bytes][n bytes][4 bytes][n bytes][4 bytes][n bytes] ....ect


my first stream consisted of [0][12][Hello World.]

_packetWriter.WriteOpCode((byte)opCode);
_packetWriter.WriteMessage("Hello World.");
_client.Client.Send(_packetWriter.GetPacketBytes());

when I read it back I get the following, and when I look at the byte arrays I'm seeing some bytes from the previous chunk

10/09/2022 11:39:00 : Opcode Found With Value 0
10/09/2022 11:39:00 : Chunk Found With Value 12
10/09/2022 11:39:00 : Message Found With Value
Hello Worl

can anybody help

thanks madaxe



C#
public class PacketWriter : BinaryWriter
    {
        public MemoryStream MemoryStream;
        public BinaryWriter BinaryWriter;

        public PacketWriter()
        {
            MemoryStream = new MemoryStream();
            BinaryWriter = new BinaryWriter(MemoryStream);
        }
        public void WriteOpCode(byte opCode)
        {
            MemoryStream.WriteByte(opCode);
        }

        public void WriteNextChunckSize(int chunkSize)
        {
            BinaryWriter.Write((Int32)chunkSize);
        }

        public void WriteMessage(string message)
        {
            WriteNextChunckSize(message.Length);
            BinaryWriter.Write(message);
        }
        public byte[] GetPacketBytes()
        {
            return MemoryStream.ToArray();
        }
    }


C#
public class PacketReader : BinaryReader
    {
        private NetworkStream _memoryStream;
        public PacketReader(NetworkStream memoryStream) : base(memoryStream)
        {
            _memoryStream = memoryStream;
        }

        public int ReadOpCode()
        {
            return _memoryStream.ReadByte();
        }

        public string ReadMessage(int chunkSize)
        {
            byte[] readMessage;
            readMessage = new byte[chunkSize];
            _memoryStream.Read(readMessage, 0, chunkSize);
            var message = Encoding.ASCII.GetString(readMessage);
            return message;
        }
        public int ReadChunkSize()
        {
            byte[] readChunkSize;
            readChunkSize = new byte[4];
            _memoryStream.Read(readChunkSize, 0, 3);
            return BitConverter.ToInt32(readChunkSize, 0);
        }
    }

GeneralRe: reading memory stream in byte chunks Pin
harold aptroot10-Sep-22 9:49
harold aptroot10-Sep-22 9:49 
GeneralRe: reading memory stream in byte chunks Pin
mjeeves10-Sep-22 10:04
mjeeves10-Sep-22 10:04 
GeneralRe: reading memory stream in byte chunks Pin
harold aptroot10-Sep-22 10:15
harold aptroot10-Sep-22 10:15 
QuestionC# Service: Error 1053: The service did not respond to the start or control request in a timely fashion Pin
temuco8-Sep-22 20:41
professionaltemuco8-Sep-22 20:41 
AnswerRe: C# Service: Error 1053: The service did not respond to the start or control request in a timely fashion Pin
Richard Deeming8-Sep-22 21:49
mveRichard Deeming8-Sep-22 21:49 
GeneralRe: C# Service: Error 1053: The service did not respond to the start or control request in a timely fashion Pin
temuco8-Sep-22 22:34
professionaltemuco8-Sep-22 22:34 
General[Solved] Re: C# Service: Error 1053: The service did not respond to the start or control request in a timely fashion Pin
temuco9-Sep-22 1:38
professionaltemuco9-Sep-22 1:38 
QuestionC# Battleship gameboard & random assignment Pin
Otto_W5-Sep-22 17:50
Otto_W5-Sep-22 17:50 
AnswerRe: C# Battleship gameboard & random assignment Pin
OriginalGriff5-Sep-22 19:11
mveOriginalGriff5-Sep-22 19:11 
GeneralRe: C# Battleship gameboard & random assignment Pin
Otto_W6-Sep-22 15:51
Otto_W6-Sep-22 15:51 
GeneralRe: C# Battleship gameboard & random assignment Pin
OriginalGriff6-Sep-22 19:19
mveOriginalGriff6-Sep-22 19:19 
GeneralRe: C# Battleship gameboard & random assignment Pin
Otto_W16-Sep-22 21:54
Otto_W16-Sep-22 21:54 
GeneralRe: C# Battleship gameboard & random assignment Pin
OriginalGriff16-Sep-22 22:13
mveOriginalGriff16-Sep-22 22:13 
GeneralRe: C# Battleship gameboard & random assignment Pin
Otto_W24-Sep-22 1:09
Otto_W24-Sep-22 1:09 
GeneralRe: C# Battleship gameboard & random assignment Pin
OriginalGriff24-Sep-22 1:34
mveOriginalGriff24-Sep-22 1:34 
GeneralRe: C# Battleship gameboard & random assignment Pin
Otto_W24-Sep-22 2:45
Otto_W24-Sep-22 2:45 
GeneralRe: C# Battleship gameboard & random assignment Pin
OriginalGriff24-Sep-22 3:16
mveOriginalGriff24-Sep-22 3:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.