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 /
This question was closed Apr 10, 2014 at 10:44 PM by zombience for the following reason:

Problem was solved, but undetermined why

avatar image
0
Question by zombience · Mar 27, 2014 at 04:34 PM · c#iosnetworksocketudp

UDPSend not working with iPad over LAN

I'm having issues broadcasting over LAN.

I don't yet know much about network best practices in .NET, so perhaps I'm taking the wrong approach. I basically took this code from an answer to another question here

I'm attempting to have two machines talk directly over a local network (trying to avoid internet connections, and hopefully avoiding MasterServer just for installation time).

I'm able to use this code to have two machines, mac or pc, talk to each other over the network. But loading the exact same project on an ipad yields nothing. I have a UDPReceiver set up, and the iPad can receive UDP messages, but is not broadcasting a return.

anyone have any insight on this? I understand that .NET sockets is restricted on iOS free version of Unity. I am using Unity Pro with iOS package.

 using UnityEngine;
 using System.Collections;
 using System.Net;
 using System.Net.Sockets;
 
 
 public class UDPSender : MonoBehaviour 
 {
 
     public int remotePort = 19800;
     public int localPort = 19801;
     public string name;
     public string IP;
     public string gameName;
 
     public string broadcastSig;
     public string broadcastMsg;
 
     protected bool refreshing;
 
     protected UdpClient sender;
 
     void OnEnable () 
     {
         sender = new UdpClient(localPort, AddressFamily.InterNetwork);
         IPEndPoint groupEP = new IPEndPoint(IPAddress.Broadcast, remotePort);
         sender.Connect(groupEP);
         IP = GetLocalIP();
         InvokeRepeating("SendData", 0, 5f);
 
     }
 
 
     void OnDisable()
     {
         if(sender != null)
             sender.Close();
     }
 
     protected void SendData()
     {
         broadcastMsg = broadcastSig + " TIME: " + Time.time.ToString();
         sender.Send(System.Text.Encoding.ASCII.GetBytes(broadcastMsg), broadcastMsg.Length);  
         Quaternion test = Quaternion.identity;
 
     }
 
 
     public string GetLocalIP()
     {
         IPHostEntry host;
         string localIP = "";
         host = Dns.GetHostEntry(Dns.GetHostName());
         foreach (IPAddress ip in host.AddressList)
         {
             if (ip.AddressFamily == AddressFamily.InterNetwork)
             {
                 localIP = ip.ToString();
                 break;
             }
         }
         Debug.Log("setting IP: " + localIP);
         return localIP;
     }
 }
 


Comment
Add comment · Show 4
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 fholm · Mar 28, 2014 at 05:24 AM 0
Share

Try using the normal System.Net.Sockets.Socket ins$$anonymous$$d of the UdpClient stuff, if you only want udp communication you can try my Udp$$anonymous$$it library, which can be found here: https://github.com/fholm/udpkit

Assu$$anonymous$$g your ports are open properly on the host computer everything should "just work" with Udp$$anonymous$$it (and normal .Net socket)

avatar image flamy · Mar 28, 2014 at 05:35 AM 0
Share

Hi @Zombience,

Are you sure you are able to send the data from PC to iPad, because usually when udp broadcast is happening, the data will be send to all the systems in the network including the one that has sent it. so if the systems and ipad are on different networks one might think that data is being recived on ipad but not send! Please confirm this...

avatar image zombience · Mar 28, 2014 at 02:27 PM 0
Share

@fholm thanks! I'll check that library out. @flamy Yup, I'm certain that it is receiving from a different source. This code right here:

 broadcast$$anonymous$$sg = broadcastSig + " TI$$anonymous$$E: " + Time.time.ToString();

uses an assignable broadcast signature, which I assign in inspector for each machine. so, sending from the PC I set it to "PC", and sending from iPad I set it to "IPAD" so I can be sure who is receiving what from whom at what time.

avatar image zombience · Apr 10, 2014 at 10:45 PM 0
Share

so, apparently this code works. not sure why it wasn't working before, but now it does. :D

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

22 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

Related Questions

LLAPI vs. pure C#.NET sockets 3 Answers

C# code run in App Console but not on Unity console 1 Answer

Multiple Cars not working 1 Answer

Unity to Node.js UDP: datagrams received are all empty. 2 Answers

Distribute terrain in zones 3 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