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 jdog98 · Nov 12, 2014 at 05:13 AM · c#arraystring

How do I send an array over the network?

Ive got an array of (string) player names that exist in my masterAdmiServer. I need the masterAdminServer to send the names to the player so the player can check to see if the name they entered is a registered username. I know how to send a single string over the network, but I need to send string[] Names; to the players. Ive tried it several different ways and get a variety of errors. C#

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by fafase · Nov 12, 2014 at 06:52 AM

Make your array a single string by concatenating them all in one:

 void SendArray(string[] str)
 {
     StringBuilder sb = new StringBuilder("");
     foreach(string s in str)
     {
          sb.Append(s+"_");
     }
     string newString = sb.ToString();
     // Send your string over the network
 }

Then you can retrieve on the other side:

 string [] SplitToArray(string str)
 {
     return str.Split('_');
 }
Comment
Add comment · Show 5 · Share
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 jdog98 · Nov 12, 2014 at 04:18 PM 0
Share

So it combines all the strings in the array into 1 string, and in that string, each piece of the array is separated by a "_". The massive string is sent over the network and the player turns the long string back into an array.

That's how it works, right?

avatar image jdog98 · Nov 12, 2014 at 04:52 PM 0
Share

I got an error, are you forgetting a using directive?

avatar image fafase · Nov 12, 2014 at 07:36 PM 0
Share

Right click on StringBuilder then Resolve. It is probably missing System.Text

avatar image jdog98 · Nov 13, 2014 at 02:35 AM 0
Share

ok, but how is it splitting the string back into an array. I mean, it splits the string, but I don't see where it puts that into an array

avatar image fafase · Nov 13, 2014 at 06:56 AM 0
Share

in the receiving script:

 string [] info = null; 
 void Receive(string str)
 {
     info = SplitToArray(str);
 }

or just:

 string [] info = null; 
 void Receive(string str)
 {
     info = str.Split('_');
 }
avatar image
1

Answer by ashique · Nov 12, 2014 at 05:36 AM

Hey..we can't send an array over network, thats why we are having collections, try to send an Object of collection like List, Set.. Thanks

Comment
Add comment · Share
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

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

27 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

Related Questions

Iterating through multidimensional arrays 2 Answers

Get JSON array object string value 2 Answers

Distribute terrain in zones 3 Answers

Value will not return from ArrayList, C# 1 Answer

String Parsing 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