- Home /
Error in UDP connection for Multiplayer Tutorial
Hi guys, I've been trying to learn multiplayer and networking with unity through the Multiplayer iPhone tutorial. Which I have been working on with windows, not the iPhone. http://download.unity3d.com/support/resources/files/MultiplayerTutorial.pdf
There seems to be an issue with setting up the UDP connection, in this part specifically:
public void start_server() {
try
{
while(true)
{
System.Text.ASCIIEncoding encode = new System.Text.ASCIIEncoding();
byte[] sendData = encode.GetBytes(Network.player.ipAddress);
server.Send(sendData,sendData.Length,ip_broadcast,System.Convert.ToInt32(port));
Thread.Sleep(100);
}
} catch {}
}
This line is the one that throws the error:
byte[] sendData = encode.GetBytes(Network.player.ipAddress);
And the error says UnityEngine.Network:Internal_GetPlayer(). I got the MasterServer working fine, but my manager also wants UDP working as well. I'm wondering if it's something to do with ports, but I'm not sure. I've looked up some docs for UDP but I am more familiar with TCP. Any advice or ideas would be greatly appreciated. Thanks!
Answer by lizzyCTS · Oct 28, 2011 at 06:00 PM
So, for this tutorial, don't use Network.player.ipAddress. When the person starts the server, it catches the ipaddress in the variable ip.
if(GUI.Button(new Rect(10,10,100,30),"Start Server"))
{
youServer = true;
Network.InitializeServer(32, listenPort);
string ipaddress = Network.player.ipAddress.ToString();
ip = ipaddress;
.....
The fix is this:
byte[] sendData = encode.GetBytes(Network.player.ipAddress);
to
byte[] sendData = encode.GetBytes(ip);
So, to all that are using this tutorial and using UDP, there's the fix.
Answer by ThiagoSCF · Dec 14, 2012 at 08:32 PM
The above answer solved my question, but for some reason I can't tumb it up.
Thank you very much
Your answer
Follow this Question
Related Questions
convert standard firstpersoncharacter into multiplayer 2 Answers
How do i make multiplayer for my game? 0 Answers
Unity Multiplayer Oyun Yapma 0 Answers
Setting up a GUI System for room selection , Multiplayer (Photon/Unet) 1 Answer
,UI Button in multiplayer Networking Game is not working...... 0 Answers