0


The question is: How to correctly set up a connection between the client, written on ActionScript, and a server, written on Java, using the NetConnection on the client side for live-streaming?

When using sockets (Socket, XMLSocket, DatagramSocket) in ActionScript, we need to provide security policy checking/answering at the server side, this process is absolutely clear and works fine.

But in case when we need to stream live media, we have to use NetConnection class instead of sockets. And this is the place where the problems begin. It looks like the NetConnection works in different way, providing a special mechanism to connect with it at the server side. The standard security policy checking, at the server side, shows that there is different data incoming from the NetConnection's instance from the client.

Here is the example of what we receive from the simple socket :

60 112 111 108 105 99 121 45 102 105 108 101 45 114 101 113 117 101 115 116 47 62 

And below is what we receive from NetConnection instance (5 tries) :

3 0 17 63 -43 -128 0 7 2 -111 101 -96 -14 -116 31 -60 56 -68 -59 33 -65 -89
3 0 17 -70 -73 -128 0 7 2 53 -16 15 -100 38 81 -84 15 -46 -53 35 112 -83 
3 0 18 11 -36 -128 0 7 2 117 -99 -103 83 25 29 -68 86 25 16 86 36 -28 
3 0 23 -60 -67 -128 0 7 2 21 -73 80 -12 80 -83 -52 68 15 37 -72 -47 11
3 0 24 36 4 -128 0 7 2 -25 42 -12 81 121 20 -52 57 -89 115 -112 76 -89

I know, NetConnection works fine with Flash Media Server, as well as Red5 and other Java-implemented web servers. So it's possible to implement this connection for sure but...

How can it be done? Any of your ideas, suggestions, examples etc. will be helpful! Thanks.

VC.One
  • 14,790
  • 4
  • 25
  • 57
Aeon
  • 35
  • 5
  • It's been a while since I did this, but if memory serves Flash sends some XML message like over the socket right after establishing the connection, and your server must reply with the cross domain policy file or the connection is dropped. I'll see if I can dig up the right part of the manual.. – Chris Kitching Mar 06 '16 at 23:29
  • @ChrisKitching Thank you for your reply! I uderstand that the NetConnection uses the same principle as a sockets when the connection is establishing, but I completely dont know what does the NetConnection send as the request (since the byte representation of this request varies, as you can see from example) and what does it expect to be the correct response... Thanks for info about "CrossDomainPolicy", i'll check this... – Aeon Mar 07 '16 at 00:18
  • Yeah, sorry I can't be more help. I did at one point write a Java server app for Flash and solve this problem, but that was 4 years ago: my memory may be out of date and so far I haven't been able to find the documentation I got it from. Good luck, hopefully someone will give you a proper answer! – Chris Kitching Mar 07 '16 at 00:20
  • Setting up RTMP is not my area, I just handle received audio/video bytes when everything is running fine.. Anyways since you get bytes `0x03` and `0x00` and so it looks like an **[RTMP handshake](http://wiki.multimedia.cx/?title=RTMP#Old_Plain_Handshake)** (some say 3-steps, some say 4-steps, yours looks like 5-steps)... Anyway maybe page 1& 2 of this **[article](http://www.actionscript.org/resources/articles/630/1/Low-level-AS3---Establishing-an-RTMP-connection-with-Socket-and-ByteArray/Page1.html)** might help you. – VC.One Mar 07 '16 at 08:14
  • Also here you are showing the decimal values of the bytes.. Did you use `trace` on bytes? Try this **[bytes to String function](https://gist.github.com/Valerio-Charles-VC1/657054b773dba9ba1cbc/#file-appendbytes_seeking_demo-as-L1480)** (sorry, couldn't find a specific small sample so just ignore the rest of code). Anyway that'll show you bytes values as you received them, since sometimes you have to **repeat exact same recieved bytes** back to the server to complete the handshake. If you saw `FFAA3C` you send `0xFF`, `0xAA`, `0x3C` instead of confusion with `-128, 20, 115` etc – VC.One Mar 07 '16 at 08:33
  • Oops forgot to mention this **[article](http://japanesesoapbox.blogspot.com/2009/11/information-that-is-missing-from-adobe.html)** too in the other comment. Might help... – VC.One Mar 07 '16 at 08:37
  • @ChrisKitching anyway, thank you for your help) – Aeon Mar 07 '16 at 12:53
  • @VC.One Thank you so much for the information you provided! You were right - this is a handshaking process. The first thing i did was a function that represents the bytes in the correct way (on the Java server). And with the second [article](http://www.actionscript.org/resources/articles/630/1/Low-level-AS3---Establishing-an-RTMP-connection-with-Socket-and-ByteArray/Page1.html) of your first message this process becomes much more clearly. – Aeon Mar 07 '16 at 13:08
  • @VC.One But I've got a new problem. I've made first 3 steps of handshaking process: 1) receive 1537 bytes from client; 2) send him 3073 bytes as the answer (formed according to the article mentioned erlier); 3) receive 1860 bytes from the client, which contain RTMP packet information (after 1536 bytes of 1860). And now I dont understand what should I do to complete this handshaking process... What is the next step? What should I send to the client to finish the handshaking and finally establish the connection? Could you help me with it, please? – Aeon Mar 07 '16 at 13:18
  • Do you have a direct link to your RTMP stream? If so then you might be working too hard here with manual handshaking etc... You should just auto-connect to the stream via AS3 code for Netstream. See this **[example Answer](http://stackoverflow.com/a/15980775/2057709)**. Show me the full URL of your test stream if possible (later you can delete that comment when you got solution if you dont want it seen by public). – VC.One Mar 08 '16 at 10:30
  • @VC.One I' trying to send the live data (audio from microphone or video from webcam) from the client to server. For that purpose I use `NetConnection` and `NetStream` at the client side, and custom java server at the server side (just a receiver java app that listens for the connections and establishes them, catches the input/output streams etc.). The server side doesn't contain any AS3 at all. It is pure Java with Java sockets and iput/output streams. At the client side, for the NetConnection object, i use this URL to connect to the server: `rtmp://152.189.33.250:8080`(IP and port of my PC) – Aeon Mar 08 '16 at 13:01
  • @VC.One The connection process begins at the client side, when the client AS3 app creates, initiates NetConnection object and calls `connect()` method with URL shown earlier. I added the event listener for the event `NetStatusEvent.NET_STATUS`, which might create a `NetStream`, if the `event.info.code` will be `NetConnection.Connect.Success`. But it is always `NetConnection.Connect.Failed` because the handshaking process isn't done in the right way. So, I need to get `NetConnection.Connect.Success` first, to work with `NetStream` – Aeon Mar 08 '16 at 13:10
  • At the server side, java app listens for the connection via ServerSocket. After connection received the server creates a new socket for connected client and extracts input/output streams. The next steps are to get the C0 and C1 from client (0x03 and other 1536 bytes), send the S0 and S1(0x03 and 1536 bytes of zeros), receive C2 (echo of S1) and send S2 (echo of C1). This works, bytes sent and received. But, from this point, I don't know what to do at all! The server sent the last thing he must to sent - the S2 answer (echo of C1). But client is still waiting for something and nothing happens – Aeon Mar 08 '16 at 13:23
  • I forgot to say: after C2, the client sends the RTMP-packet that contain the appropriate info. This is good, but... what is the next step?) The client is still waithing for something after that. and I don't know what to send him from server as the correct response (to see the `NetConnection.Connect.Success` message at the client and move further)... – Aeon Mar 08 '16 at 14:01
  • Like I said in my first comment... "**setting up an RTMP server is not my area**" (can handle RTMP data during playback phase). You have access to the server so you already see or know more than me. Try things suggested in the article or check the RTMP Specifications PDF. Also you need to create an application stream to connect to (both recorder and viewer must connect to that. You cannot use same NC object to record & watch the stream so create 2 separate netConnections whilst testing. `nc_toServer = new NetConnection();` as recorder **vs** `nc_fromServer = new NetConnection();` as playback – VC.One Mar 12 '16 at 05:17
  • Anyways.. at the bottom of that **[article](http://www.actionscript.org/resources/articles/630/1/Low-level-AS3---Establishing-an-RTMP-connection-with-Socket-and-ByteArray/Page1.html)** he tries a `nc.call( "connect" , null );` and those bytes are server response. Do you get the same (check AS3, check Java)? If yes, then just create an application stream to connect AS3 with. It might be enough to just have a **folder** of video **as app**. eg: `rtmp://152.189.33.250/someFolder/testVid.flv` test AS3 netconnection to this. If `NetConnection.Connect.Success` then its sorted. – VC.One Mar 12 '16 at 05:25

0 Answers0