Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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.

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

How can i make a boat transport? 1 Answer

How can I read data sent using the Transport API with python server 1 Answer

Convert to entity script causes Unity to crash? 1 Answer

ECS mesh dissapears on camera move in Game or Scene 0 Answers

DOTS Grid-based generation question. 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