Hi.
I now making some game by unity.
So question is same with title, how integrate between unity client part and existing delphi server part?
How communicate between?
Thanks in advance.
Hi.
I now making some game by unity.
So question is same with title, how integrate between unity client part and existing delphi server part?
How communicate between?
Thanks in advance.
that would be through System.Net and then TCP Socket / UDP Socket or their client pendants.
See MSDN for documentation of the options
Thx deamora have you checked PM?
and can you let me know search keyword in MSDN site?
also I now using javascript in unity.
Using javascript in Unity doesn’t change the functions and classes to use. But you won’t find any examples naturally.
As for what to search: Look for the System.Net namespace and the TCP - UDP related classes there.
If you don’t know how that works then it makes no sense to search though then you better ask your dev that wrote the delphi server on the whole matter and potentially let him do it cause he will need to write thread code etc
So server guy says delphi server must receive UDP packets from unity. I googled about javascript and UDP, people says javascript don’t have UDP classes.
Then this means I must use C# to sending UDP packet to delphi server?
Or other solution?
You must not google for javascript, UnityScript (or unhappily called javascript) has nothing to do with what you find when you search for javascript on google which is for browser.
As mentioned you won’t find any documentation on it either as Sockets are a .NET feature and UnityScript is no general .NET language its a unity specific one.
but the commands are the same independent on if you use C# or UnityScript, just go to the MSDN and read up on the UDP Client class and other UDP classes to see what fits your needs best.
that or learn C# (not that hard actually if you are versed in UnityScript and thats required anyway to work with threads and sockets) and then you have examples too.
ok Thanks.
I am confident in UnityScript, but not in C#, so I can understand from your answer,
I can refer MSDN’s C# example of UDP Client, and use it samely in UnityScript.
Point me if I am wrong.
Thanks again.
Nope thats exactly the path I tried to point out in both posts above ![]()
Take the C# example and port to UnityScript. This kind of porting is pretty straight forward normally too
Just ensure that you switch to .NET 3.5 versions of sample codes cause Unity has no .NET 4.0 and the samples sometimes differ especially with this kind of asyncronous topic
I met problem.
I copied and pasted c# example code in this page,
but this does not work in unity.
I made c# script in unity and then paste this code after default,
using UnityEngine;
using System.Collections;
Why and how must be revised?
Thx.
Dig deeper young padawan. By defeating those nasty line of codes and making them work you can hope the CODE will be with you at some point in the future.
And have patience padawan, one error at the time…
P.S. Dreamora was kind enough to guide you to the solution, but dont expect him to solve the problem for you. Nor anyone else, unless you pay. It’s study time ![]()
I see.
so PM me with your portfolio/or proof you can do this and price if you are confident.
Work is unity javascript client ↔ delphi server part Integration. Not so much big game but small and simple turn game.
OK, not interested in learning Delphi at this point, but i took a moment and adapted the code from MSDN for you. The code is C# because I dont have time to convert it to unity pseudo javascript. Also make sure the project where are you trying this is set to publish to desktop not webplayer (for webplayer you need Unity - Scripting API: Security.PrefetchSocketPolicy).
This is the unity client part, can be attached to any object:
using UnityEngine;
using System;
using System.Collections;
using System.Net;
using System.Net.Sockets;
using System.Text;
public class client : MonoBehaviour
{
private UdpClient udpClient;
private IPEndPoint RemoteIpEndPoint;
private byte[] receiveBytes;
private string returnData;
// Use this for initialization
void Start ()
{
// This constructor arbitrarily assigns the local port number.
udpClient = new UdpClient(11000);
udpClient.Connect("192.168.1.3", 11000);
//IPEndPoint object will allow us to read datagrams sent from any source.
RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);
try
{
// Sends a message to the host to which you have connected.
byte[] sendBytes = Encoding.ASCII.GetBytes("Is anybody there?");
udpClient.Send(sendBytes, sendBytes.Length);
// Blocks until a message returns on this socket from a remote host.
receiveBytes = udpClient.Receive(ref RemoteIpEndPoint);
returnData = Encoding.ASCII.GetString(receiveBytes);
// Uses the IPEndPoint object to determine which of these two hosts responded.
Debug.Log("This is the message you received " + returnData.ToString());
udpClient.Close();
}
catch (Exception e)
{
Debug.Log(e.ToString());
}
}
// Update is called once per frame
void Update ()
{
}
}
and this is the server code from Simple Udp Server : Udp Server « Network « C# / C Sharp just changed the port to 11000.
Thx for reply.
I tried your code, attaching that client.cs to main camera and build standalone and run, or just run in unity editor, unity just stops and crashed.
and I also tried this, http://forum.unity3d.com/threads/15900-simple-udp-implementation-(send-read-via-mono-c-)?highlight=udp+packet
but this seems does not work when I change IP and port from default (127.0.0.1) to some real specific server IP like (97.220.8.30)
Well i presume it crashed because it doesn’t find the server. Hanged for me too several times when testing, because i forgot to start the server first. Also the IP should be the the IP of the server.