• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Pitrees · Sep 04, 2020 at 09:51 AM · dotstransport

Unity Transport API, how to writebytes & readbytes for texture data?

I'm trying to send texture/image bytes data to server. But keep getting ArgumentOutOfRangeException: Specified argument was out of the range of valid values. at stream.ReadBytes(array);

Please help guide me.

Client

 public void SendBytes(string title, Texture2D _tex)
 {
     if(!m_Connected)
         return;
         byte[] buffer = _tex.GetRawTextureData();
         var array = new NativeArray<byte>(buffer, Allocator.Temp);
         Debug.Log("Send bytes with Length " + array.Length);
         var writer = m_Driver.BeginSend(m_Connection);
         writer.WriteString((NativeString64)title);
         writer.WriteInt(array.Length);
         writer.WriteBytes(array);
         m_Driver.EndSend(writer);
 }

Server

 public void ProcessByteImage(DataStreamReader stream)
 {
 int bufferLength = stream.ReadInt();
 Debug.Log("Get bytes with Length " + bufferLength);
 Debug.Log("Stream Length = "+stream.Length);
 byte[] recBuffer = new byte[stream.Length];
 var array = new NativeArray(recBuffer, Allocator.Temp);
 
 stream.ReadBytes(array);
 recBuffer = array.ToArray();
 
 texture2d = new Texture2D(2,2,TextureFormat.RGB24,false);
 texture2d.LoadRawTextureData(recBuffer);
 texture2d.Apply();
 
 _rawImageBytes.texture = texture2d;
 }










Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image andrew-lukasik · Sep 09, 2020 at 07:30 PM 0
Share
 texture2d = new Texture2D(2,2,TextureFormat.RGB24,false);

This line hard coded expected raw data to be 12 bytes long. While it's not responsible for this exact exception but will be the next one :).

avatar image andrew-lukasik · Sep 09, 2020 at 07:53 PM 0
Share

As to ArgumentOutOfRangeException: Specified argument was out of the range of valid values my guess is that array from stream.ReadBytes(array) is of length 0.

avatar image AlexanderSinaisky andrew-lukasik · Oct 01, 2021 at 09:20 PM 1
Share

Becouse UDP can send only 65535 bytes in each packet. Unity use UDP.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

138 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Character Can't Move After Position Change 1 Answer

Using ECS to place 150,000 corn stalk models is less efficient than placing 300,000 corn stalk models on the detail layer of terrain? 1 Answer

ECS entity not rendering? 1 Answer

DOTS storing navmesh data in sharedComponent? 1 Answer

How to access bounds of entity in ECS ? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges