While testing and analyzing code of Bluetooth Chat, I have questions about my own program.
a) My program sends a command to another bluetooth device. (I can handle it using sample code provided)
b) It then receives a response to my previous command.
c) Based on the response received, my device sends another command.
d) It then receives a response to my command.
and the same procedure continues ...
My question is , in Bluetooth Chat program there is a handler which receives a response. How can I make sure to receive first response and then used that to send another command ... and then receive a response again based on second command, using that same handler.
My question is , in Bluetooth Chat program there is a handler which receives a response. How can I make sure to receive first response and then used that to send another command ... and then receive a response again based on second command, using that same handler.
How about using a state machine?
Related
I've been experimenting with SignalR client in an Android app connecting to a C# server hub.
When the Main Activity launches I want to invoke a call to grab the current List data from the server and call back when it's received so the RecyclerView can be loaded
However I can't seem to get the HubConnection.Invoke method to return a value, I've confirmed the hub is certainly receiving the request and is returning a value with the below;
public async Task GetActiveAlarms()
{
Console.WriteLine("GetActiveAlarms Called");
await Clients.Caller.SendAsync("GetActiveAlarms", Program.activeAlarms);
}
In the client I am calling using the below and using the doOnComplete callback
hubConnection.invoke("GetActiveAlarms").doOnComplete {
//is never called
}.blockingAwait()
However the .on listener for "GetActiveAlarms" is called, which indicates the hub is receiving the request and responding.
Unfortunately I can't find a huge amount of information on the SignalR library for Java so I may be doing it all wrong.
Thanks!
Change your hub method to return the value instead of sending a message back to the client.
e.g.
public string GetActiveAlarms()
{
Console.WriteLine("GetActiveAlarms Called");
return Program.activeAlarms;
}
Hi I am writing a telegram client using https://github.com/rubenlagus/TelegramApi that listen to incoming messages but I noticed some relevant messages carried in 'Polls' could not be read.
After a few debugging, it appears when such message is received, the incoming 'MessageMedia' part of the TLMessage being deserialized is mapped to messageMediaUnsupported#9f84f49e
According to documentation it means it is 'not supported by current client version'.
Indeed, I could see no implementation for messageMediaPoll message media in org.telegram.api.message.media package, and I could add it. But, how to have the server consider my client as valid for receiving such media?
I been trying to understand how bacnet java works on device reply “iam” message to the respective call
For example:
1. Device 5678 send broadcast message with new whois message(device id 1234)
2. Device 1234 replies “iam” message to device 5678.
Questions
How device 1234 send “iam” message to 5678?
Which part of JAVA code does that??
I'm happy for any input on the subject.
Best regards
Sorc
who-is and i-am are both unconfirmed BACnet services.
when a who-is is sent (broadcast or unicast) by a device, other devices present in network reply with i-am.
assuming that you are using java based BACnet stack (library) to create your own application. your application will receive i-am, that received from network in the form of callback from stack library.
in general the stack (implemented in any programming language) will decode this data and pass it to application in the form of callbacks.
hope this helps you.
On the basis that the Who-Is broadcast contains the SADR/source address, the receiving devices knows where to send it's response - if it did want to give a unicast/directed response.
You then have to listen out for the UDP (- UDP/IP -) response, and then you have to parse it, for the Object ID.
Actually for my server game I'm not using Netty. I've created a socket multithreaded system for send packet object who is serialized into and deserialized from (Int and Out)StreamBuffer.
I've discovered Netty and I think it's better to use it for my network system.
I've actually created a Client and Server handler (both extends ChannelInboundHandlerAdapter) to serialized and deserialized my packet from the ByteBuf, it's work FINE :) !
Now I want migrate my authentication system.
Actually, I've two Handler, the LoginHandler which can receive and process only the Login Packet (defined by an id when I send a buffer packet), and the ServerHandler which can receive and process all others packets.
Actual algorithme
Client side :
User launch a client a new window ask him to enter his username and password When he click on "Login", the client connect to the server, and after send a LoginPacket.
If a AuthServerPacket is sent by the server with the auth flag to true, he continue and open all others features.
If a AuthServerPacket is sent by the server with the auth flag to false, it display a popup with the reason, and re-open the window login.
Server side :
When a user is connecting to the server it's the LoginHandler which is attached to the client.
In this LoginHandler, only LoginPacket is processed, so, when it receive a LoginPacket it check the informations in a database, if these are correct, the client are added to the ServerHandler and deleted from the LoginHandler, and now he can receive and send all others packets.
ServerHandler send a AuthServerPacket with auth flag to true.
My question is, what is the best way to re-create this system with Netty ?
I don't know if I can add the login handler in the pipeline which it will be not check it if a channel is authentified. I don't know how or if the process is stopped if one of the handler reject the channel.
Someone can help me to understand what is the best way to do what I want with Netty ?
Thanks you in advance for your answers.
Programmatically, beaucoralk.
we talked on IRC #netty today :)
My suggestion is:
In your Pipeline Initializer, always add the LoginHandler
Once Login is successful, then the LoginHandler should:
ctx.pipeline.addAfter(this, "gameHandler", new GameLogicHandler());
ctx.pipeline.remove(this);
So basically your LoginHandler removes itself, after a successful authentication. Important: add the new Handler before removing the old Handler. :)
best regards
I've solved my problem with this :
In my Pipeline Initialize always add the LoginHandler (don't add my ServerHandler)
Once Login is successful, then the LoginHandler do :
ctx.pipeline.addLast(new GameLogicServerHandler());
ctx.pipeline.remove(this);
In fact I have not succeeded to use the addAfter like said Franz Bettag, no method was appropriate.
But thanks you to Bettag who help me to understand many things on #netty IRC.
I have an interface that I've exposed as a regular SOAP web service. One method of the interface consists for the client to send a file to the server, then the server processes the file and returns a result file. Processing the file may take some time, so I think using asynchronous invocation of this method is a better idea. I thought about the following flow:
The client invokes the asynchronous method and sends the file using an attachment (MTOM).
When the file is received by the server, a response is sent back to the client indicating that the file has been received and that it will be processed shortly.
Once the file is processes, a response is sent back to the client indicating it has been processed and a result file is returned in the response also as an attachment.
Is it possible using SOAP with CXF?
Thanks
You can use Callback approach of Asynchronous InvocationModel.
Callback approach - in this case, to invoke the remote operation, you
call another special method that takes a reference to a callback
object (of javax.xml.ws.AsyncHandler type) as one of its parameters.
Whenever the response message arrives at the client, the CXF runtime
calls back on the AsyncHandler object to give it the contents of the
response message
More information can be had from the following:
Apache CXF
If you use some tool like WSDL2Java for client generation, you can even choose to generate an asynchronous client.
It will generate for you a callback handler with empty methods for each of the service operations and exceptions of the service. You then can just implement those methods to set the actions to do when the response is received.
Remember that when an asynchronous call is done a new thread is started.
Yes, Once you receive the file, you may return the request id to client and start processing on server side and do maintain various states of processing. Client can come back in different interval, and will receive the processing status or the output if it is completed.