For last project i was need show part of main display to distant big screen, connected to another PC. So i need somehow send video feed via Ethernet. Firstly i tried find any encoder lib for sending h264 video, but this was so complicated. So i did small Socket server in adobe air for this distant big screen PC and wrote some code in c# for unity client.

There is 2 ways for sending images to flash via sockets.

1. Send uncompressed bitmap data (ARGB = 4 bytes) from Unity and then use bitmapData.setPixels(rect, byteArray) for recteate bitmap
2. Convert bitmap data into PNG in Unity via Texture2D.EncodeToPNG and them use Loader.loadBytes() in flash.

some code below


Unity part

using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
//

public class NetworkConnection : MonoBehaviour
{
	private int R_WIDTH = 480;
	private int R_HEIGHT = 384;

    public string server_IPAdress = "192.168.0.30";
    public int server_Port = 3333;
    public Socket m_Socket;

	private Texture2D tex;
	private int frame=0;

	private byte[] byteArray;

    void Start()
    {
    	//prepare bytearray for colordata
		byteArray = new byte[R_WIDTH*R_HEIGHT*4];
		// temp texture for store part of screen
		tex = new Texture2D(R_WIDTH,R_HEIGHT,TextureFormat.RGB24,false);
		Connect();
    }

	void Update(){
		if (!m_Socket.Connected) return;
	    StartCoroutine(TakeSnapshot());
	}

	public IEnumerator TakeSnapshot(byte mode)
	{
	    yield return new WaitForEndOfFrame();
	    // grab part of screen
		tex.ReadPixels(new Rect(0, 0, tex.width,tex.height), 0, 0);
		
		// pack texture colordata to bytearray
		int b = 0;
		int y = R_HEIGHT-1;
		Color c;
        while (y >= 0) {
            int x = 0;
            while (x < R_WIDTH) {
                c = tex.GetPixel(x,y);
				byteArray[b++] = 255;
                byteArray[b++] = (byte) (c.r*255);
				byteArray[b++] = (byte) (c.g*255);
				byteArray[b++] = (byte) (c.b*255);
                ++x;
            }
            --y;
        }

		 // convert string length value to network order
		 int reqLenH2N = IPAddress.HostToNetworkOrder(byteArray.Length);
		 // get string length value into a byte array -- for use with
		 byte[] reqLenArray = BitConverter.GetBytes(reqLenH2N);
		 // send the length value
  		 m_Socket.Send(reqLenArray, 4, System.Net.Sockets.SocketFlags.None);
		 // send imagebytearray
		 m_Socket.Send(byteArray);

	}

    /// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    public void Connect()
    {
		Debug.Log("trying to connect");
        IPEndPoint ipep = new IPEndPoint(IPAddress.Parse(server_IPAdress), server_Port);
        m_Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
        try
        {
            m_Socket.Connect(ipep);
        }
        catch (SocketException e)
        {
            Debug.Log("NO Connect "+e.Message+" "+e.TargetSite);
            return;
        }
    }
    void OnApplicationQuit()
    {
		if (m_Socket != null){
        	m_Socket.Close();
		}
    }
}

as3 part

package {
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.ProgressEvent;
	import flash.events.ServerSocketConnectEvent;
	import flash.net.ServerSocket;
	import flash.net.Socket;
	import flash.utils.ByteArray;
	[SWF(backgroundColor="#000000", frameRate="31", width="480", height="384")]
	public class SocketReceiver extends Sprite {
		private var serverSocket : ServerSocket = new ServerSocket();
		private var clientSocket : Socket;
		private var localPort : int = 3333;
		private var localIP : String = "192.168.0.30";
		private var bitmap : Bitmap;
		private var imageLength : int = 0;
		public function SocketReceiver() {
			bitmap = new Bitmap(new BitmapData(480, 384, false, 0x0000));
			addChild(bitmap);
			bind();
		}
		private function bind() : void {
			if ( serverSocket.bound ) {
				serverSocket.close();
				serverSocket = new ServerSocket();
			}
			serverSocket.bind(localPort, localIP);
			serverSocket.addEventListener(ServerSocketConnectEvent.CONNECT, onConnect);
			serverSocket.listen();
		}
		private function onConnect(event : ServerSocketConnectEvent) : void {
			clientSocket = event.socket;
			clientSocket.addEventListener(ProgressEvent.SOCKET_DATA, receivedData);
		}
		private function receivedData(ev : ProgressEvent) : void {
			if (imageLength == 0) {
				imageLength = clientSocket.readInt();
			}
			if (clientSocket.bytesAvailable >= imageLength) {
				var bArray : ByteArray = new ByteArray();
				clientSocket.readBytes(bArray, 0, imageLength);
				imageLength = 0;
				bArray.position = 0;
				bitmap.bitmapData.setPixels(bitmap.bitmapData.rect, bArray);
			}
		}
	}
}