guys i add this csharp code to my Main Camera GameObject and when i start the game unity3d stops responding… whats wrong?
using UnityEngine;
using System;
using System.Net;
using System.Collections;
using System.Data;
using MySql.Data.MySqlClient;
using System.Net.Sockets;
public class NewBehaviourScript : MonoBehaviour {
public string informationLabelText;
TcpListener server = null;
// Use this for initialization
void Start () {
try
{
Int32 port = 13000;
IPAddress localAddr = IPAddress.Parse("127.0.0.1");
server = new TcpListener(localAddr,port);
//start listening for clients
server.Start();
Byte[] bytes = new Byte[256];
string data = null;
while(true)
{
informationLabelText = "Waiting for a Connection";
//Perform a block call to accept requests
//you can also use server.AcceptSocket(); here
TcpClient client = server.AcceptTcpClient();
informationLabelText = "Connected";
data = null;
//get a stream object for reading and writing
NetworkStream stream = client.GetStream();
int i;
//loop to receive all the data sent by the client
while( (i = stream.Read(bytes, 0, bytes.Length) ) !=0 )
{
data = System.Text.Encoding.ASCII.GetString(bytes,0,i);
//TODO SEE IF USERNAME PASSWORD EXISTS
data = "accepted";
byte[] msg = System.Text.Encoding.ASCII.GetBytes(data);
stream.Write (msg,0,msg.Length);
informationLabelText = "Information Sent";
}
//shut down & end connection
client.Close();
}
}
catch(SocketException e)
{
informationLabelText = e.ToString();
}
finally
{
//stop listening for clients
server.Stop();
}
}
// Update is called once per frame
void Update () {
}
}