Search Unity

  1. Engage, network and learn at Unite Austin 2017, Oct 3 - 5. Get your ticket today!
    Dismiss Notice
  2. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  3. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  4. Unity 2017.1 is now released.
    Dismiss Notice
  5. Unity 2017.2 beta is now available for download.
    Dismiss Notice

Sockets in flash?

Discussion in 'Flash' started by klad, Jun 15, 2012.

  1. klad

    klad

    Joined:
    Jul 13, 2011
    Posts:
    16
    Hello!

    I have a web application built in unity than opens a socket to a server. This works just fine, but when i try to convert this application to Flash, i get the following conversion errors:

    Code (csharp):
    1.  
    2. Error building Player: Exception: Compiling SWF Failed:
    3. Loading configuration file C:\Program Files (x86)\Unity\Editor\Data\PlaybackEngines\flashsupport\BuildTools\flex\frameworks\flex-config.xml
    4.  
    5. E:\SocketFlashTest\Temp\StagingArea\Data\ConvertedDotNetCode\global\SocketManager_AsynchronousClient.as(125): col: 79 Error: Type was not found or was not a compile-time constant: IAsyncResult.
    6.  
    7.         public static function AsynchronousClient_ConnectCallback_IAsyncResult($ar: IAsyncResult): void {
    8.                                                                                     ^
    9.  
    10. E:\SocketFlashTest\Temp\StagingArea\Data\ConvertedDotNetCode\global\SocketManager_AsynchronousClient.as(141): col: 69 Error: Type was not found or was not a compile-time constant: Socket.
    11.  
    12.         public static function AsynchronousClient_Receive_Socket($client: Socket): void {
    13.                                                                           ^
    14.  
    15. E:\SocketFlashTest\Temp\StagingArea\Data\ConvertedDotNetCode\global\SocketManager_AsynchronousClient.as(151): col: 79 Error: Type was not found or was not a compile-time constant: IAsyncResult.
    16.  
    17.         public static function AsynchronousClient_ReceiveCallback_IAsyncResult($ar: IAsyncResult): void {
    18.                                                                                     ^
    19.  
    20. E:\SocketFlashTest\Temp\StagingArea\Data\ConvertedDotNetCode\global\SocketManager_AsynchronousClient.as(194): col: 73 Error: Type was not found or was not a compile-time constant: Socket.
    21.  
    22.         public static function AsynchronousClient_Send_Socket_String($client: Socket, $data: String): void {
    23.                                                                               ^
    24.  
    25. E:\SocketFlashTest\Temp\StagingArea\Data\ConvertedDotNetCode\global\SocketManager_AsynchronousClient.as(199): col: 76 Error: Type was not found or was not a compile-time constant: IAsyncResult.
    26.  
    27.         public static function AsynchronousClient_SendCallback_IAsyncResult($ar: IAsyncResult): void {
    28.                                                                                  ^
    29.  
    30. E:\SocketFlashTest\Temp\StagingArea\Data\ConvertedDotNetCode\global\SocketManager_StateObject.as(14): col: 39 Error: Type was not found or was not a compile-time constant: Socket.
    31.  
    32.         public var StateObject$workSocket$: Socket;
    33.                                             ^
    34.  
    35. E:\SocketFlashTest\Temp\StagingArea\Data\ConvertedDotNetCode\global\SocketManager_StateObject.as(7): col: 27 Error: Definition System.Net.Sockets:Socket could not be found.
    36.  
    37.     import System.Net.Sockets.Socket;
    38.                              ^
    39.  
    40.  
    Means this that sockets are not available on flash version? If they are, how should we use them so we do not get these errors?

    Thanks in advance!
     
  2. RalphH

    RalphH

    Unity Technologies

    Joined:
    Dec 22, 2011
    Posts:
    589
    Sockets are not support. Can't provide for the functionality that the Socket class has. Instead you can write your own C# glue layer on top of pure actionscript using the UnityEngine.FlashApi and the ability to compile in ActionScript in your project.
     
  3. catburton

    catburton

    Joined:
    Mar 29, 2011
    Posts:
    43
    Here is a very basic example of how to implement sockets in AS3.

    There are only 3 classes in this example:
    • TestRunner.cs - A MonoBehaviour residing on the camera in the scene. Creates a new ActionScriptSocket instance and requests to connect to the socket. This class also has a function to display the socket response (called from the AS3 class).
    • ActionScriptSocket.as - Has functionality for connecting to and returning results from the socket. Will call a method on the TestRunner to display any connection results or errors.
    • ActionScriptSocket.cs - A proxy script with the same public API as the ActionScript version.

    View attachment $Sockets.zip
     
  4. whgandalf

    whgandalf

    Joined:
    Nov 20, 2009
    Posts:
    2
    I have downloaded the files, but I dont not how to make them work, can you give me some tips! :)