I'm a bit confused. I would like to send messages from my Red5 Server to my Flash App... but I don't find any information how to do that...
Can anyone help me?
This looks like a good start:
http://www.red5tutorials.net/index.php/Tutorials:Getting_Started_With_Red5_Server
See near the bottom for their simple flash client.
Edit: More options given now that it's clear we're going from server-client:
Looks like you need to do something like this:
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/NetConnection.html
and
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/NetStream.html
which would mean using "NetStream.play()" to get the server to stream data to the client.
Or you might want to look at the Socket class(es) and manually create a direct socket connection between the client and server.
Keep in mind here, I've never used Red5. Just trying to help :)
For anyone who didn't find an answer until today: I am working in red5, and you can send message from red5 to flash by a RemoteSharedObject in AS3 connecting to a sharedobject in red5.
Server Code:
ISharedObject so = getSharedObject(scope, "chat");
so.setAttribute("message","Welcome");
Client Code:
so = SharedObject.getRemote("chat", connection.uri, false);
so.connect(connection);
so.addEventListener(SyncEvent.SYNC, syncChatHandler);
private function syncChatHandler(event:SyncEvent):void {
Alert.show(so.data.message,"Information");
}
This code will show an alert on users connected with the message "Welcome". From here read a lot of documentation and use your imagination.
Hmm, by definition, the server serves and the client requests. So to create a push scenario, you still have to first initialize a connection from the client to the server. Then you can leave the connection idle until you need to send something to the client. Polling is the other method, where the server holds on to the messages and the client frequently checks in to see if new messages are available. A server cannot initiate a connection to the client. That would make the client a server. In other words, you could have the flash client register it's current IP with the server and open up a port itself, establishing itself as a server. Then the Red5 server becomes a client and can connect to the server inside the flash client. But I imagine many security restrictions will prevent your flash program from acting as a server in the real world.
Related
Is it possible to connect to a server like "www.google.com" for example server side. Not actually connecting through google.com but that is the idea.
ServerSocket serverSocket = new ServerSocket(0, 50, InetAddress.getByName("www.google.com"));
This code returns null, I am new to this connection related stuff so I don't know exactly what that would be meaning.
This is the code I have currently for setting up the server, it works fine when using localhost, but I am unsure on how to continue with an actual domain and server so anyone can connect and communicate.
If it isn't possible to set up a server like that, what is the best way to implement and I am trying to do.
you can open raw sockets to whatever you want, but a ServerSocket is if you want to be a server, not if you want to connect to one; you'd use normal Socket for that.
sockets is for raw TCP/IP. You run some service on top of it. For example, HTTP or HTTPS, which is what the web runs on, is built on top of it.
I really doubt you want to write an HTTP client just for www.google.com, it's rather complicated. Fortunately, java has one built in. Don't use Socket, use HttpClient.
See the java HTTP client tutorial here.
There is an existing service that i would like to write a dummy service (using Netty) for. It will be used for testing purposes.
The existing client code fragment for the service looks like:
Socket socket = new java.net.Socket();
socket.connect(new InetSocketAddress("localhost", 8080), 10000);
socket.setSoTimeout(20000); // set a timeout of 20 seconds
InputStreamReader ir = new InputStreamReader(socket.getInputStream());
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
// write some string to the server and wait for answer
out.println("SomeCommand");
// server has written some answer, read it
char[] c = new char[2];
ir.read(c, 0, 2);
String cs = new String(c);
if ("OK".equals(cs.toString())) {
// write some more string's to the server
}
// we're done, close the connection
out.println("BYE");
out.close();
socket.close();
Is Netty the right framework to create a server for java.net.Socket connections? (If not, which framework should be used, if any?)
I am trying to find a way to start with Netty using the QuoteOfTheMoment example. The QuoteOfTheMomentServerHandler does basically what i want, upon the incoming message, return some answer so that the above snippet can read the answer using the inputstream but the above socket cannot make a connection to the QuoteOfTheMomentServer. The error is "connection refused".
[EDIT] More clarification:
The problem (i think) is not connecting or the port i use. Let me try to better ask the question:
I just started with netty (no nio experience) and am not familiar with the different types of channels, pipelines and what not.
The server should, like a servlet request/response (like, not http or trying to rebuild a http servlet impl), react on a inputString written to the output-stream as in the code fragment and write back some string/bytes to the input-stream as in the code fragment, so the client only then moves on. So the connection should stay open but also be synchronous, the client waits for answer from the server. If i use the example "Writing the Server Side of a Socket" in the java tutorial i am able to get it working for the client. But i want to utilize the thread handling etc. from netty.
The QuoteOfTheMomentServerHandler seems as server side implementation what i want but can that setup handle the given client code ?
So the question is which kind of pipeline, channel or something like that should be used given the way the client works ?
Again, the client and server are existing. I want to build a dummy server implementation to work with the existing client.
Netty is a TCP/IP framework. So yes if you are developing a TCP/IP server this toolkit is good to use.
I assume you are getting a error when trying to connect the client to the server. Also the server should also be running.
When getting a the connection refused error there are a couple of thine to check. First one is the firewall(if any) on the server allowing connections to port 8080? Secondly from your client machine try open a telnet session to the server something like:
Telnet yourserverip 8080
This opens a socket connection to the server. If you get a error message Google it.
The last one is that you might be running a server like tomcat, glassfish, IIS which uses port 8080 already. Try a non standard port like 10810 for example.
UPDATES:
If you are new to netty please read the users guide found here http://netty.io/docs/stable/guide/html/.
I had a look at the Quote of the moment service and I do believe I found part of the problem. The Quote of the moment service is a broadcast UDP/IP client and server. UDP is a much more lightweight "version" of TCP IP. It does not guarantee delivery to the client or server and it is broadcast. UDP is sort of like a radio broadcast as it is generally not targeted to a specific IP but broadcast over the entire network. Thus you normal TCP IP connection will not be able to work on the UDP server.
See this link on how to write a UDP Client http://systembash.com/content/a-simple-java-udp-server-and-udp-client/.
I would suggest that you convert the Quote of the moment server from UDP to TCP/IP server as this will give you some practise in creating a TCP/IP server without getting into too much detail. Once you are comfortable with that you should be able to start once from scratch.
Just remember that Netty handles the NIO part for you. It is a higher level framework based on NIO thus hiding a lot of the detail from you. You dont need to know NIO that well to use netty but you need to understand the Netty concepts well.
I am working on a project in which I can see webcam images from the people who is in front of the door on my Android app.
But I am getting a bit confused. I've managed to setup a connection with a service on my phone to a server which handles the image sending.
But i only want to get images from the server when someone presses the doorbell, so I need to send a notification or something to my app so I know there is one in front of the door, and I want to decide if I want to answer his call or not.
Now this is why I am confused: if I open the tcp socket in the android service, how can I know that my server sends a 'call' message, because the tcp socket is openend when the service is created. Do I need to keep polling every second? Then there is still a little chance that I will miss the call message?
Or do I have to run the application as server and the doorbell as client, so the client request a connection?
Have a look at cloud to device messaging, c2dm , a lot more power efficient too. Built into android.
https://developers.google.com/android/c2dm/
If the tcp socket is opened when the service is created, just send some appropriate message from the server to connected clients. If your client is connected, it will get it. You only need to poll if the client continually connects and disconnects, eg. like many HTTP 1 web services.
I am trying to write a piece of software that
accept simple UDP messages (text strings) from simple UDP client,
opens connection to another server and forwards messages to it
listens for that server reply and
forwards that reply back to the client.
So it is a simple intermediate server.
To visualise the communication:
Client <---> Intermediate Server <---> "Real" Server
The client connects to the Intermediate but has no idea that the message it sends is being forwarded to another server, or that it's reply is actually from another server. As far as the client cares it the Intermediate server is the real server.
I am trying to use Java's DatagramChannel for this, but not quite sure how to correctly do this in a non-hack way. Do I use two DatagramChannels? One for Client--Intermediate and the other for Intermediate--Real Server?
An general outline of approach would be appreciated, particularly if I need to open a socket every time I need to forward a message from the Intermediate to the Real Server, or if I can keep that socket open somehow.
You only need one datagram socket for this, and you can keep it open for the life of the process.
I have something like a proxy server (written in java) running between my clients and the actual video server (made in c++). Everything the clients send goes through this proxy and is then redirected to the server.
It is working fine, but I have some issues and think it would be better if I could make this proxy server only to listen to the clients requests and then somehow tell the server that a request has been made from the client side, and that it is supposed to create a connection with the client directly.
Basically in the TCP level what I want to happen is something like this:
1- whenever a client sends a SYN to my proxy, the proxy just sends a message to the real server telling the ip and port of the client.
2- The server would then send the corresponding SYN-ACK to the specified client creating a direct connection between client and server.
The proxy would then be just relaying the initial requests (but not the later data transfer) to the actual server. I just don't know if that is possible.
Thank you very much
Nelson R. Perez
That's very much the way some games (and Fog Creek CoPilot) do it, but it requires support on both the server and the client. Basically the proxy has to say to the client and server "try communicating with the directly on this ip and this port" and if they can't get through (because one or both is behind a NAT or firewall), they fall back to going through the proxy.
I found this good description of "peer to peer tcp hole punching" at http://www.brynosaurus.com/pub/net/p2pnat/
Does the proxy and server lives on the same machine? If so, you can pass the connection to the server using Socket Transfer or File Descriptor Passing. You can find examples in C here,
http://www.wsinnovations.com/softeng/articles/uds.html
If they are on the different machines, there is no way to pass connection to the server. However, it's possible to proxy the IP packets to server using VIP (Virtual IP). This is below socket so you have to use Link layer interface, like DLPI.
You don't have control of TCP handshake in userland like that. This is what firewalls/routers do but it all happens in the kernel. Take a look at the firewalling software for your platform - you might not even have to code anything.