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
2
Question by eheimburg · Feb 16, 2013 at 10:30 AM · networksocketplay moderecompile

Keep network socket open during play mode recompile

I have custom networking code using the C# Tcp socket classes. Works great. The only problem comes when I edit a script during play mode -- when any script is recompiled during play, my socket connection is lost, my C# TcpClient object becomes invalid, and my game crashes.

Is there any way to keep a socket open between recompiles? (Unity's internal networking classes do it, so they should have exposed some way for us to do it, too, since they claim to fully support custom network solutions... there shouldn't be anything a custom network solution can't theoretically do!)

And if there really isn't a way to keep a socket open (and a reference to that socket handy, so I can communicate with it), is there a way to stop the Automatic-Recompile-During-Playmode feature? Currently, editing a script during play mode will lock up my machine as it generates thousands of errors related to the now-missing socket.

Thanks for any insights you might have here!

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

Answer by TheMaragnus · Mar 11, 2015 at 01:37 PM

I know that this is an old question, but it has left me stumped for months.

The route that I'm going is to serialize the IP endpoint and handshake information from the connection and reinitialize the socket on Awake of my network manager ScriptableObject. The server code simply needs to keep a List of client endpoints and their identity from the client handshake and it should not have a problem. Just recreate the socket on Awake. With UDP, it is rather trivial since connections are artificial anyway.

This, in theory, should work for TCP as well. You'll just need to prepare for two methods of connection handshake: "New Connection" and "Resume Connection". The client will need to know to automatically reconnect to a server that drops it using the "Resume Connection". And the server will need to be prepared to accept clients back that drop suddenly, and cache any information about to be sent incase it fails.

Also relevant is the Serialization help article that shows how to custom serialize data. You could use OnBeforeSerialize and OnAfterDeserialize to serialize dictionaries or any custom network information that you require.

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
avatar image
0

Answer by kirpigiller · Feb 16, 2013 at 11:18 AM

is your Socket object a static object? Does it have any static fields of methods? This can cause the problem

Comment
Add comment · Show 1 · 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 eheimburg · Feb 16, 2013 at 12:04 PM 0
Share

Just tonight I've made it a public member of a $$anonymous$$onoBehaviour and put [Serializable] on all the members of my class... this keeps the object from going away, but the TcpClient seems to be in an invalid state afterwards. And it disconnects the socket, so even if the C# object was valid, the connection is still broken

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

11 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

Related Questions

LLAPI vs. pure C#.NET sockets 3 Answers

.NET Socket Support for iOS/Android Basic 4 Answers

Unity Network if use GameObject.Instantiate() the program will disconnect 0 Answers

PrefetchSocketPolicy. The server is not mine. How can I talk to him using .NET Sockets ? 0 Answers

Global update function for network 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