Hi there,
i am using Unity from a couple of months, but this is the first time, i am unable to fix a bug i am having.
I am using UdpClient, to send, and another UdpClient to receive, the scripts I am using are taken from here.
I have changed that instead of comunicating in local (127.0.0.1) it comunicates to the string ip.
As all tutorials say, when testing a network i should do a Standalone Build to test the connection with the editor.
I did the same, but
My build is sending the message to the editor, and editor receives it.
My editor sends the message to the build, but build does not receive it.
Then to test, where is the problem, i cloned the project as âProject - Copyâ, and opened it in a separate Editor.
Connecting Editor1 to Editor2, worked perfectly, sending and receiving is done properly on both.
But tried the same, by building the app, and open it twice, Build1 and Build2 no one receives anything.
I am sure there is no problem in sending, because perhaps Build sends the message to the Editor, and editor receives it.
I am sure there is no code problem in receiving, because editor1 and editor2 comunicates perfeclty.
I have no problems with Windows Firewall, i gave it the access to all the network.
What is the problem that in editor everything works fine, and the builded does not?
Hope someone can help, any idea would be appreciated.
Thanks a lot.
bye!
With the informations provided, I see only limited reason for it to not work aside of 2:
-
The code in that thread, especially the last one, violates Unity standards in multiple ways which might cause it to break on builds (that would be visible in the output_log.txt in the appname_data folder on windows or the console/unity/unity_player.log on osx)
-
You might be trying to get mobile devices working like that. in that case its relevant to know that the whole system.net namespace requires mobile pro licenses to be usable at all.
Could you perform your tests again with a similar version of above code that I wrote and shared in 2011 on the topic of Unity Script + Threaded UDP? It should still work.
You can download it from https://dl.dropboxusercontent.com/u/83083/Unity/UdpClient_UnityScript.unitypackage
Note: The code was originally written for Unity 3 when Unity did not check for some cross thread access. to make this work properly you must remove the âTime.timeâ part as UT decided to make this a âbreaking callâ from other threads despite it being a static read access.
oh yaa tested, it works fine! now I am going to convert this to c# and connect it with my project, and then i will let you know
thanks a lot.
but it only works in local host (127.0.0.1), i am trying to implement it to reach LAN
Within local LAN on wifi / cable, the code still should work if you provide the correct IPs and if the software firewall on the âserverâ node allows the incoming message on the specified port to go through.
If the network has a router or small business switch in you need to ensure that they allow the message to pass through the network.
Some wifi routers offer âguest networksâ or âisolatedâ modes where different devices are unable to see each other within the WIFI for security reasons. In such a network, its technically impossible to create an MP game locally.
I am trying to see this, but first i would like to have in C#, as to have it compatible with the rest of the project. but I am getting this error:
client = new UdpClient (port);
I have tried different ports 51, 513, 427, randomly selected from here.
what is the cause of this?
- and why also when I am working on Network (dealing with System.Net, âŚ) my editor crashes after script compilation,
I have seen, that when working on other scrips, and these network scripts are not in the project everything goes fine, but once i start to work on this scripts (in any project) that causes my editor (4.5.5f1) to crash after script compilation, so i go in task manager, force close it, and everything is okay.
What is the cause?
I am working on a Asus K55V, (Intel I7 3630QM, 6GB Ram) and a Toshiba Satellite (Intel I7 4th gen, 16 GB Ram)
After changing that code line to
try {client = new UdpClient (port);}catch (Exception error) {Debug.Log (error.ToString ());}
I get this log each frame.
at this codeline
byte[] data = client.Receive (ref ip);
what is the cause of this? where I am doing wrong?
It needs to be
IPEndpoint ipep = new IPEndpoint(IPAdress.any, Port);
Endpoint ep = (Endpoint)ipep;
byte[] data = new byte[your lenght, eg 1024];
int recv = client.receiveFrom(data, ep);
Or something in those ways. For the specific things, just look at msdn
EDIT: The int btw gives you the number of sent bytes, so you can read the written bytes in your buffer (data in this case) and wonât get any \0\0\0⌠(Nullbytes I suppose)