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 ikelaiah · Aug 15, 2013 at 03:23 AM · networkingwebplayerudp

How can I receive UDP packets into Unity Webplayer?

I am building a simple webplayer that accept remote user input. However, I can't seem to send anything into it. The programs below compiles file and run fine, but will not receive anything. I tried port 1023 - 25000, no avail. I am running this from Unity Editor. I use free UDP Test tool to send message to 127.0.0.1. When I re-do this code for a C# console application, it works well. But not from Unity Webplayer build. Could someone help?

 using UnityEngine;
 using System.Collections;
 
 using System;
 using System.Net;
 using System.Net.Sockets;
 using System.Threading;
 using System.Text;
 
 public class UDPDemo : MonoBehaviour {
     
     private UdpClient receivingUdpClient;    
     private IPEndPoint remoteIpEndPoint;
 
     private Thread thread;
     
     // port number
     private int receivePort = 843;
     
     // Use this for initialization
     void Start () {
         try {
             receivingUdpClient = new UdpClient(receivePort);
         } catch (Exception e) {
             Debug.Log (e.ToString());
         }
         
         remoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);
 
         // start the thread for receiving signals
         thread = new Thread(new ThreadStart(ReceiveDataBytes));
         thread.Start();
         
         // debug
         Debug.Log("Thread started");
     }
     
        
     void ReceiveDataBytes() {
         while (true) {
             Debug.Log ("Threading inside while");
             // NOTE!: This blocks execution until a new message is received
             Byte[] receivedBytes = receivingUdpClient.Receive(ref remoteIpEndPoint);
             String receivedStringData = Encoding.ASCII.GetString(receivedBytes);
             Debug.Log ("I received : " + receivedStringData);
             Debug.Log ("The message was sent from " + remoteIpEndPoint.Address.ToString() + " on port number " + remoteIpEndPoint.Port.ToString());
 
             Thread.Sleep(8);
         }
     }
     

     void CloseClient() {
         thread.Abort();
         receivingUdpClient.Close();
     }
     
     void OnApplicationQuit() {
         CloseClient();
     }
 }
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
1
Best Answer

Answer by ikelaiah · Aug 20, 2013 at 01:35 AM

Finally! I'll answer my own question again. After googling and digging into Unity forum, documentation (see here, and here, see how it begins with "In Unity 3.0...") and Answer website (see this and this one too), I found the answer! I come to a conclusion that the answer (at the moment) is ...

NOT POSSIBLE

...but there are workarounds, such as this one.

Comment
Add comment · Show 3 · 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 bustedkrutch · Nov 20, 2013 at 04:50 AM 0
Share

If you could please share your work arounds, it would be much appreciated as I'm facing the same issue.

Thank you

avatar image Bunny83 · Nov 20, 2013 at 05:25 AM 1
Share

The usual workaround is to not use UDP but using TCP. That way the webplayer can open the connection and once open you can send and receive data.

UDP is connection-less, so each packet is on it's own. When Unity wants to receive a packet from a remote source, it would have to connect to the policy port, load the crossdomain.xml and check if it's allowed to receive from this source. That would be required for every packet (since connection-less).

Also i doubt that binding to "any" would work in the webplayer, but i'm not sure when and how Unity does it's policy check.

avatar image ikelaiah · Nov 21, 2013 at 12:21 AM 0
Share

Yes, TCP makes sense than UDP in this case. I updated my answer with Flynn's thread.

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

17 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

[MMO - Everquest] How to connect Unity to a non-unity Server? 1 Answer

UDP/TCP Simple example on how to send a receive messages from two Unity builds 2 Answers

How can I get deep info on configuration of Unity networking? 0 Answers

Do i need networking? 0 Answers


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