Ok, så testing some TCP communication and seem to be doing something wrong. I have a server up and running and and i can get connect to it, but i cant seem to get the Send()-function to work.
Here is the code:
public string m_IPAdress = "localhost";
public const int kPort = 8085;
private static Main singleton;
private Socket m_Socket;
void Start () {
m_Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
// System.Net.PHostEntry ipHostInfo = Dns.Resolve("host.contoso.com");
// System.Net.IPAddress remoteIPAddress = ipHostInfo.AddressList[0];
System.Net.IPAddress remoteIPAddress = System.Net.IPAddress.Parse(m_IPAdress);
System.Net.IPEndPoint remoteEndPoint = new System.Net.IPEndPoint(remoteIPAddress, kPort);
singleton = this;
m_Socket.Connect(remoteEndPoint);
print("Socket connected = "+m_Socket.Connected);
}
void OnGUI()
{
//print("in ongui");
if (GUI.Button(new Rect(100, 100, 100, 30), "Ping"))
{
sendPing();
}
}
void sendPing()
{
if (m_Socket.Connected)
{
string testData = "<Ping />";
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
byte[] bTest = encoding.GetBytes(testData);
singleton.m_Socket.Send(bTest);
print("Data sent..." + bTest.Length);
}
}
Now, Unity tells me my socket is indeed up and running, but as i execute singleton.m_Socket.Send(bTest), nothing happends. What am i doing wrong?
Thanks in advance…