Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Henry_V · Feb 24, 2017 at 09:50 AM · multiplayer-networkingsocket

Multiplayer with sockets

Hi guys! I'm i'm going to graduate this year and I'll have to make a graduation project so I was thinking to use unity, which I already more-or-less know (I have already made some games). This will be a two-players multiplayer game, and I was wondering how could I make the networking part work. Since this is a school project I'd rather not use networking tools which Unity provides, I would prefer to write myself lower level networking functions (maybe with sockets). I will have to sync positions of game objects in real-time (like one would do in a online fps). Should I use UDP? On which interval should I sync the objects' position? And how should I design the message passed between the clients? I'm completely new to networking programming (I only made a chat program with c# and TCP sockets, just for testing), so if you could answer those questions or if you had some advice about multiplayer programming patterns I would be very grateful :) Anyway, thank you for your time!

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

1 Reply

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

Answer by hrgchris · Feb 24, 2017 at 12:26 PM

Hi Henry

There's quite a bit of detail there. To answer a few bits:

  • UDP will give you quite a few headaches, as it doesn't guarantee a message will arrive, or in what order messages will arrive. You will likely have some essential messages, and if relying solely on UDP you would have to implement reliable message schemes which are pretty tricky

  • TCP unfortunately can create a lot of latency. It can be a helpful way to get started, however for real time syncing of object positions it probably won't end up suitable

  • It's not unusual (especially in prototypes) to open 2 sockets - 1 TCP and 1 UDP, then use TCP for critical, not time dependent messages, and UDP for ones that you can afford to lose!

However! Given this is a graduation project in Unity, and you want to give yourself some degree of lower-level networking challenge, can I suggest you go half way and use Unity's Network Transport Layer: https://docs.unity3d.com/Manual/UNetUsingTransport.html

It's a very low level wrapper around Unity's internal network code. The high level UNet stuff uses the transport layer for communication, but you can access it too without using UNet.

You'd still need to properly handle network messages, think about reliable/unreliable messaging, message formats, timings, bandwidth and synchronise objects and stuff yourself. You just wouldn't need to deal with the very low level issues of opening a socket, reliable queues or async network events (which I can promise from past experience are serious time sinks - you could probably do an entire thesis just on that!).

For message formats, look into the BitConverter in .net for converting values to/from byte arrays to be sent over the network.

Hope that helps

-Chris

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 Henry_V · Feb 24, 2017 at 02:24 PM 0
Share

Thank you! Tips like "open two sockets, an udp one and a tcp one" were the ones I was after, I didn't think about that at all. Yes, the main purpose of this project will be to kind of show what I've learned in my school years and how can I apply this knowledge to real world applications so I will probably make a very simple game (like, maybe, Battleship) and implement all of the controls and features. I think I'll try to design an AI and multiplayer. For that I'll use and manage myself the transport layer networking (and all of its problems!), maybe trying with C# sockets and async program$$anonymous$$g and, if I see it's too much work, switch to Unity's Network Transport Layer. Just for my personal enjoyment, if it all works right, I was thinking to make it VR with Google Cardboard, that would be probably a lot of fun. Anyway, thank you for your answer!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to get string as a response of socket !? 0 Answers

How to set namespace in packet of socketIO using unity3d 1 Answer

Socket programming in unity 3 Answers

IOS socket connection to java socket server 0 Answers

Using mono socket with IPv6 and TCP 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