In Atmosphere Framework onDisconnect() method is not working for me if Network cable is connected, but when I close the browser it's working.
What is the solution to solve this?
This is my code:
public void onDisconnect(AtmosphereResourceEvent event)
{
logger.trace("", event);
if (event.isCancelled()) {
when request.enableProtocol
} else if (event.isClosedByClient()) {
}
}
Related
I ran a thread that updates the open time of the application. It works well. I've expanded the Service class. The time from this task update my GUI, textField by Platform.runLater
#Override
protected Task<Void> createTask() {
return new Task<Void>() {
#Override
protected Void call() throws Exception {
while (!isCancelled()) {
if (isPause == false) {
try {
Platform.runLater(() -> {
currentTimeInApp = currentTimeInApp + 1;
upPanelController.timeInApp.setText
(currentTimeInApp.toString());
}
});
Thread.sleep(1000);
} catch (InterruptedException e) {
System.out.println(e.getMessage());
}
if (isCancelled())
break;
}
}
return null;
}
};
}
I would like to run a second thread which also updates GUI. I can't run the same thread. Can two independent threads be updated GUI ?
Most of the information on the internet is dedicated to one topic. Thank you for every suggestion
Yes, you can use as many threads as you like. You just have to make sure that you always do the GUI update via Platform.runLater.
Hello, i have been working on this problem for 3 days and i cant figure out what is wrong with it. The error message i got is "SpawnObject for Player(Clone) (UnityEngine.GameObject), NetworkServer is not active. Cannot spawn objects without an active server." i know that the server is starting fine because when i connect to it with a client then close the server the client says that the server may have shutdown. Here is the code i have so far. THANK YOU IN ADVANCE
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
using System.Collections;
public class MENU_CONTROLLER : NetworkBehaviour
{
public GameObject ipField;
public GameObject connectButton;
public GameObject hostButton;
public GameObject player;
public Text ip;
public Text PlayerCount;
private int playercount = 0;
void Update() {
}
void vanishMenu() {
ipField.SetActive(false);
connectButton.SetActive(false);
hostButton.SetActive(false);
}
public void ServerConnect() {
Network.Connect(ip.text.ToString(), 4444);
vanishMenu();
SpawnPlayer();
}
public void SpawnPlayer() {
GameObject p = (GameObject)Instantiate(player, transform.position,transform.rotation);
NetworkServer.Spawn(p);
}
public void ServerStart() {
Network.InitializeServer(30, 4444, true);
Network.Connect("localhost", 4444);
SpawnPlayer();
}
void OnPlayerConnected(NetworkPlayer player) {
playercount++;
print("PLAYER CONNECTED");
print(player.ipAddress);
PlayerCount.text = playercount.ToString();
}
}
You must call the NetworkServer.Spawn() from within an "is server" block.
if (is Server) {
//do your thing to spawn
}
So I've been following this Android Tutorial (Youtube) by Derek Banas. Trying to learn to make a NavigationDrawer.
I run into onAttach() being deprecated. I looked at this Stack Overflow link but I'm a beginner in AS and can't understand if it's correct (mainly due to me not sure if I have to instantiate MTitle, mCalled, mHost,etc) and how I can possibly implement it, in my app.
onAttach code:
public void onAttatch(Activity activity) {
super.onAttach(activity);
((MainActivity)activity).onSectionAttached(1);
}
public void onSectionAttached(int number) {
switch(number) {
case 1:
mTitle = getString(R.string.title_section1);
break;
}
Try
public void onAttach(Context context){
super.onAttach(context);
...
}
Vaadin newbie: When a user presses a button, I like to disable it so he knows that he clicked it and there's some work going on in the background. When the (long) task is completed, I'd like to enable the button.
For this, I'm using 2 threads (background and work) but for some reason the button doesn't enabled at the end of the task.
In other words, once clicked it goes to enabled(false) and never coming back. Why? and how can I fix it?
button.addClickListener(new ClickListener()
{
public void buttonClick(ClickEvent event)
{
Thread background = new Thread(new Runnable(){
#Override
public void run()
{
Thread work = new Thread(new Runnable(){
#Override
public void run()
{
button.setEnabled(false);
try
{
Thread.sleep(2000); //long work here!
} catch (InterruptedException e)
{
e.printStackTrace();
}
button.setEnabled(true); //doesn't enable at the end of the long work!
}});
work.start();
try
{
work.join();
} catch (InterruptedException e)
{
e.printStackTrace();
}
}});
background.start();
}
});
Maybe the best approach would be to use Button.setDisableOnClick(true) for the button and do the processing directly in the event handler without a background thread. This will show the standard loading indicator to the user until processing is done.
Otherwise you need to enable server push (#Push) and remember to use UI.access() in the background thread before updating the UI. See https://vaadin.com/book/-/page/advanced.push.html
I have a C program and that runs a web server. I have a Air Application and I want to communicate with that web server using Air Application. I create a socket object and do the following.
public function httpTest():void
{
sock.addEventListener(Event.CONNECT, onConnect);
sock.addEventListener(ProgressEvent.SOCKET_DATA, onDataRecv);
sock.addEventListener(IOErrorEvent.IO_ERROR, onError);
try
{
trace("Connecting...");
sock.connect("127.0.0.1", 9800);
sock.writeMultiByte("GET /Connection?data=version", "us-ascii");
sock.flush();
}
catch(err:Error)
{
trace(err.message);
}
}
public function onConnect(event:Event):void
{
trace("onConnect +");
}
public function onDataRecv(event:ProgressEvent):void
{
trace("onDataRecv +");
}
public function onError(event:Event):void
{
trace("onError +");
}
socket connects successfully and its connection event is fired. but when I try to request the connection url nothing is received on server side. am I missing something. Thanks
Like just about everything to do with networking in Flex, socket.connect is asynchronous and non-blocking, meaning that just because sock.connect has returned without error it doesn't mean the socket is actually ready for use yet. I suspect that if you put trace(sock.connected) in your original code after your call to writeMultiByte it will print false.
You will need to delay your sock.writeMultiByte call until the connection is ready, which isn't until your onConnect handler fires. Try:
try
{
trace("Connecting...");
sock.connect("127.0.0.1", 9800);
}
catch(err:Error)
{
trace(err.message);
}
...
public function onConnect(event:Event):void
{
trace("onConnect +");
sock.writeMultiByte("GET /Connection?data=version", "us-ascii");
sock.flush();
}
I made a mistake. I did not add HTTP version and string terminator in the Get String. Thats why I did not receive any print on server side. Because the request was invalid. I posted the working code. Thanks for help.
public function httpTest():void
{
sock.addEventListener(Event.CONNECT, onConnect);
sock.addEventListener(ProgressEvent.SOCKET_DATA, onDataRecv);
sock.addEventListener(IOErrorEvent.IO_ERROR, onError);
try
{
trace("Connecting...");
sock.connect("127.0.0.1", 9800);
sock.writeMultiByte("GET /Connection?data=version HTTP/1.0\r\n\r\n", "us-ascii");
sock.flush();
}
catch(err:Error)
{
trace(err.message);
}
}
public function onConnect(event:Event):void
{
trace("onConnect +");
}
public function onDataRecv(event:ProgressEvent):void
{
trace("onDataRecv +");
}
public function onError(event:Event):void
{
trace("onError +");
}