I am having a problem where an object with a byte [20] passed in a compilation of intercept on a thread and a thread The object being returned using a blocking collection returns a byte [0]. I think this is a threading issue, but I do not know why blocking compilation is a concurrent collection, due to this why this is happening.
Sometimes at thread 2, myclass2.mybytes byte is equal to [0]. Any information about how to fix this is greatly appreciated.
[edit] Original code I removed the code above which was just running fine, so I took the time to post it by writing my original code.
MessageBuffer.cs
Public Message MessageBuffer: BlockingCollection & LT; Message & gt; {} In the class that is the listener () and ReceivedMessageHandler (object messageProcessor)
Private MessageBuffer RecievedMessageBuffer; on Thread1
Private Zero Audience () {while (this.IsListening) {try {Message Message = Message.ReadMessage (this.Stream, this ); If (message! = Null) {this.RecievedMessageBuffer.Add (message); }} Hold (IOException pre) {if (! This.Client.Connected) {this.OnDisconnected (); } Else {Logger.LogException (ex.ToString ()); This.OnDisconnected (); }} Hold (Exception pre) {Logger.LogException (ex.ToString ()); This.OnDisconnected (); }}} Message.ReadMessage (NetworkStream section, iTcpConnectClient customer)
public static message ReadMessage (NetworkStream section, iTcpConnectClient customer) {int ClassType = - 1; Message message = null; {Try ClassType = stream.ReadByte (); If (classotype == -1) {return tap; } If (! Message. Aiaitiosielasskkantenski ((byte) Clastaip)) (New Aioakseshn ( "Class type not found");} Message = MessagekGetNewMessage ((byte) Clastaip); message. The client = client; message.ReadData (Section); if (message. buffer. exceed & lt; message.MessageSize + Message.HeaderSize) {return null;}} catch (IOException ex) {Logger.LogException (ex.ToString ()); East;} catch ( Exception pre) {Logger.LogException (ex.ToString ()); // pre-throw;} return message;} at thread2
private void ReceivedMessageHandler (object messageProcessor) {if (messageProces sor! = NULL) {while (this.IsListening) {message = this.RecievedMessageBuffer.Take (); message.Reconstruct (); message.HandleMessage (messageProcessor);}} and {while (this.IsListening) {message = This is the Recipient Message Buffer.Take (); message.Reconstruct (); message.HandleMessage ();}}} PlayerStateMessage.cs
Public class player message: Message {public GameObject PlayerState; Public override int messages {get {return 12; }} Public PlayerState Message (): Base () {this.PlayerState = new GameObject (); } Public PlayerState Message (GameAbject PlayerState) {this.PlayerState = playerState; } Public override zero reconstruction () {this.PlayerState.Poisiton = this.GetVector2FromBuffer (0); this. PlayerState.Ronption = ItGetflotFonFfFor (8); Base.Reconstruct (); } Public override zero Deconstruct () {this.CreateBuffer (); This.Ad.Obuffer (it. PlayerState.Posten, 0); this. Adotbuffer (This. PlayerState Rotation, 8); Base.Deconstruct (); } Public Override Zero Handle Message (Object Message Processor) {(Message Processing) Message Processors. Processesplayerstate Message (this); }} Message.GetVector2FromBuffer (integer bufferlocation) This is where the exception is thrown because this.Buffer byte [0] when it should be byte [20]. <> public Vector2 GetVector2FromBuffer (integer bufferlocation) pre {return new Vector2 (BitConverter.ToSingle (this.Buffer, Message.HeaderSize + bufferlocation), BitConverter.ToSingle (this.Buffer, Message.HeaderSize + bufferlocation 4)); }
So there was a difficult problem to solve it. As far as I know, I was just getting a random byte, so I changed my "message" quite a bit. Now there is a header buffer and a data buffer, the entire message is explained with the initial marker and the closing marker, while the header and data buffers are interpreted by each individual markers. It has allowed me to tell that if I get poor data then I can abandon the message. If the message is removed, instead of just checking it on the next check, instead of checking that the first 4 bytes have been received, this is the initial marker, byte byte will be read, until the last 4 bytes read marker Are not equal
Comments
Post a Comment