I am trying to develop a flutter app which connects to the server and exchanges data using websocket. The server is in .Net Core and using Asp.Net Core Websockets to implement this functionality.
The problem I am facing is, my flutter app is not able to connect to the server and throws following error.
E/flutter (31498): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter (31498): WebSocketChannelException: WebSocketChannelException: WebSocketException: Connection to 'http://127.0.0.1/client#' was not upgraded to websocket
E/flutter (31498): #0 new IOWebSocketChannel._withoutSocket.<anonymous closure> (package:web_socket_channel/io.dart:83:24)
E/flutter (31498): #1 _invokeErrorHandler (dart:async/async_error.dart:13:29)
E/flutter (31498): #2 _HandleErrorStream._handleError (dart:async/stream_pipe.dart:286:9)
E/flutter (31498): #3 _ForwardingStreamSubscription._handleError (dart:async/stream_pipe.dart:168:13)
E/flutter (31498): #4 _RootZone.runBinaryGuarded (dart:async/zone.dart:1328:10)
E/flutter (31498): #5 _BufferingStreamSubscription._sendError.sendError (dart:async/stream_impl.dart:350:15)
E/flutter (31498): #6 _BufferingStreamSubscription._sendError (dart:async/stream_impl.dart:367:16)
E/flutter (31498): #7 _BufferingStreamSubscription._addError (dart:async/stream_impl.dart:266:7)
E/flutter (31498): #8 _SyncStreamController._sendError (dart:async/stream_controller.dart:767:19)
E/flutter (31498): #9 _StreamController._addError (dart:async/stream_controller.dart:647:7)
E/flutter (31498): #10 _RootZone.runBinaryGuarded (dart:async/zone.dart:1328:10)
E/flutter (31498): #11 _BufferingStreamSubscription._sendError.sendError (dart:async/stream_impl.dart:350:15)
E/flutter (31498): #12 _BufferingStreamSubscription._sendError (dart:async/stream_impl.dart:367:16)
E/flutter (31498): #13 _BufferingStreamSubscription._addError (dart:async/stream_impl.dart:266:7)
E/flutter (31498): #14 _SyncStreamController._sendError (dart:async/stream_controller.dart:767:19)
E/flutter (31498): #15 _StreamController._addError (dart:async/stream_controller.dart:647:7)
E/flutter (31498): #16 new Stream.fromFuture.<anonymous closure> (dart:async/stream.dart:110:18)
E/flutter (31498): #17 _RootZone.runBinary (dart:async/zone.dart:1386:54)
E/flutter (31498): #18 _FutureListener.handleError (dart:async/future_impl.dart:141:20)
E/flutter (31498): #19 Future._propagateToListeners.handleError (dart:async/future_impl.dart:649:47)
E/flutter (31498): #20 Future._propagateToListeners (dart:async/future_impl.dart:670:24)
E/flutter (31498): #21 Future._completeError (dart:async/future_impl.dart:489:5)
E/flutter (31498): #22 Future._asyncCompleteError.<anonymous closure> (dart:async/future_impl.dart:537:7)
E/flutter (31498): #23 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
E/flutter (31498): #24 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
Important thing here is, the app is able to connect to other websocket servers. It can also connect to other prototype servers that I developed for testing on the same machine.
The .Net core server is also very functional and I can connect a browser easily to the server and communicate with it.
The problem just arises only when I try to connect a flutter app to a .Net core websocket server.
I am using the default template app for testing. Here is the code of my MyHomePage class
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final channel = new IOWebSocketChannel.connect("ws://192.168.1.139/client");
Here is the _MyHomePageState implementation
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
initState() {
super.initState();
widget.channel.stream.listen(this.onData, onError: onError, onDone: onDone);
(() async {
setState(() {
});
});
}
onDone(){
debugPrint("Socket is closed");
}
onError(err){
debugPrint(err.runtimeType.toString());
WebSocketChannelException ex = err;
debugPrint(ex.message);
}
onData(event){
debugPrint(event);
}
which always results in onError with following output
I/flutter ( 4608): WebSocketChannelException
I/flutter ( 4608): WebSocketChannelException: WebSocketException: Connection to 'http://18.217.117.92/client#' was not upgraded to websocket
I/flutter ( 4608): Socket is closed
I understand it has to do something with how dart websocket package perform the handshake with server but not able to pin point the issue.
Can anyone please figure out what exactly is wrong here ?
I hope this will help many though the issue is no longer relevant. The problem is with .Net core websocket implementation.
With some research and after analyzing the Wireshark log, I could realize that somehow .Net core expected the websocket protocol update headers in specific format (i.e. the implementation was case sensitive) this is true for .Net core framework 2.1. However, the problem was immediately fixed in the next release. I switched to beta and the issue was fixed. I consulted both Flutter developers as well as .Net core team regarding this and they confirmed the same.
The current version of .Net core (at the time of answering this is 3.0 which has no such problems.
Related
I deployed Laravel 9 on localhost and everything was good. When I deployed on cpanel shared hosting, I am getting this error.
Your assistance will be appreciated.
Here are some of the steps I have taken on the localhost but no difference on the shared hosting:
I have cleared the bootstrap contents
composer dump-autoload
: Uncaught ReflectionException: Class "config" does not exist in xx/xx/xx/xx/vendor/laravel/framework/src/Illuminate/Container/Container.php:875 Stack trace: #0 xx/xx/xx/xx/vendor/laravel/framework/src/Illuminate/Container/Container.php(875): ReflectionClass->__construct('config') #1 xx/xx/xx/xx/vendor/laravel/framework/src/Illuminate/Container/Container.php(756): Illuminate\Container\Container->build('config') #2 xx/xx/xx/xx/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(855): Illuminate\Container\Container->resolve('config', Array, true) #3 xx/xx/xx/xx/vendor/laravel/framework/src/Illuminate/Container/Container.php(692): Illuminate\Foundation\Application->resolve('config', Array) #4 xx/xx/xx/xx/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(840): Illuminate\Container\Container->make('config', Array) #5 xx/xx/xx/xx/vendor/laravel/framework/src/Illuminate/Container/Container.php(1415): Illuminate\Foundation\Application->make('config') #6 xx/xx/xx/xx/vendor/laravel/framework/src/Illuminate/Log/LogManager.php(515): Illuminate\Container\Container->offsetGet('config') #7 xx/xx/xx/xx/vendor/laravel/framework/src/Illuminate/Log/LogManager.php(566): Illuminate\Log\LogManager->getDefaultDriver() #8 xx/xx/xx/xx/vendor/laravel/framework/src/Illuminate/Log/LogManager.php(119): Illuminate\Log\LogManager->parseDriver(NULL) #9 xx/xx/xx/xx/vendor/laravel/framework/src/Illuminate/Log/LogManager.php(636): Illuminate\Log\LogManager->driver() #10 xx/xx/xx/xx/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(275): Illuminate\Log\LogManager->error('Call to undefin...', Array) #11 xx/xx/xx/xx/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(415): Illuminate\Foundation\Exceptions\Handler->report(Object(Error)) #12 xx/xx/xx/xx/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(113): Illuminate\Foundation\Http\Kernel->reportException(Object(Error)) #13 /home2/phenhost/public_html/index.php(52): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request)) #14 {main} Next Illuminate\Contracts\Container\BindingResolutionException: Target class [config] does not exist. in xx/xx/xx/xx/vendor/laravel/framework/src/Illuminate/Container/Container.php:877 Stack trace: #0 xx/xx/xx/xx/vendor/laravel/framework/src/Illuminate/Container/Container.php(756): Illuminate\Container\Container->build('config') #1 xx/xx/xx/xx/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(855): Illuminate\Container\Container->resolve('config', Array, true) #2 xx/xx/xx/xx/vendor/laravel/framework/src/Illuminate/Container/Container.php(692): Illuminate\Foundation\Application->resolve('config', Array) #3 xx/xx/xx/xx/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(840): Illuminate\Container\Container->make('config', Array) #4 xx/xx/xx/xx/vendor/laravel/framework/src/Illuminate/Container/Container.php(1415): Illuminate\Foundation\Application->make('config') #5 xx/xx/xx/xx/vendor/laravel/framework/src/Illuminate/Log/LogManager.php(515): Illuminate\Container\Container->offsetGet('config') #6 xx/xx/xx/xx/vendor/laravel/framework/src/Illuminate/Log/LogManager.php(566): Illuminate\Log\LogManager->getDefaultDriver() #7 xx/xx/xx/xx/vendor/laravel/framework/src/Illuminate/Log/LogManager.php(119): Illuminate\Log\LogManager->parseDriver(NULL) #8 xx/xx/xx/xx/vendor/laravel/framework/src/Illuminate/Log/LogManager.php(636): Illuminate\Log\LogManager->driver() #9 xx/xx/xx/xx/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(275): Illuminate\Log\LogManager->error('Call to undefin...', Array) #10 xx/xx/xx/xx/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(415): Illuminate\Foundation\Exceptions\Handler->report(Object(Error)) #11 xx/xx/xx/xx/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(113): Illuminate\Foundation\Http\Kernel->reportException(Object(Error)) #12 /home2/phenhost/public_html/index.php(52): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request)) #13 {main} thrown in xx/xx/xx/xx/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 877
I have configured server. At last I am getting this issue to make connection.
This is New Linux server as per http://157.245.105.194/test.php
Let me know what is wrong in the code given at : https://docs.google.com/document/d/1M0iqC4_5kGQVgR6aKhKFAwxbpwTOyYN7PyEgjBfL3mQ/edit?usp=sharing
At http://157.245.105.194/styleogram/fs/site/wwwroot/public/
we are getting:
===========
Notice: Undefined index: db_host in /var/www/html/styleogram/fs/site/wwwroot/app/config/config.php on line 56
Notice: Undefined index: db_user in /var/www/html/styleogram/fs/site/wwwroot/app/config/config.php on line 57
Notice: Undefined index: db_password in /var/www/html/styleogram/fs/site/wwwroot/app/config/config.php on line 58
Notice: Undefined index: db_name in /var/www/html/styleogram/fs/site/wwwroot/app/config/config.php on line 59
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [1045] Access denied for user ''#'localhost' (using password: NO)' in /var/www/html/styleogram/fs/site/wwwroot/app/config/config.php:60
Stack trace:
#0 [internal function]: PDO->__construct('mysql:host=;dbn...', NULL, NULL, Array)
#1 [internal function]: Phalcon\Db\Adapter\Pdo->connect(Array)
#2 /var/www/html/styleogram/fs/site/wwwroot/app/config/config.php(60): Phalcon\Db\Adapter\Pdo->__construct(Array)
#3 [internal function]: {closure}()
#4 [internal function]: Phalcon\Di\Service->resolve(NULL, Object(Phalcon\Di\FactoryDefault))
#5 [internal function]: Phalcon\Di->get('db', NULL)
#6 [internal function]: Phalcon\Di->getShared('db')
#7 [internal function]: Phalcon\Mvc\Model\Manager->_getConnection(Object(Article), NULL)
#8 [internal function]: Phalcon\Mvc\Model\Manager->getReadConnection(Object(Article))
#9 [internal function]: Phalcon\Mvc\Model->getReadConnection()
#10 [internal function]: Phalcon\Mvc\Model\Query->_executeSelect(Array, Array, NU in /var/www/html/styleogram/fs/site/wwwroot/app/config/config.php on line 60
===========
The error you see is because your $_SERVER superglobal does not contain the elements you are looking for in your code. You can easily see this in the phpinfo() page you posted (check Apache Information section).
$connection = new MysqlAdapter(
[
"host" => $_SERVER['db_host'],
"username" => $_SERVER['db_user'],
"password" => $_SERVER['db_password'],
"dbname" => $_SERVER['db_name']
]
];
You can remove the references to the $_SERVER array and use strings with the actual information for your installation. For instance $_SERVER['db_host'] could be localhost for you.
Once you do those replacements, check if the error persists - if not, then you have connected to your database correctly.
You can also use the Phalcon\Config object to store configuration data, such as database connection parameters as defined above, instead of setting them in the $_SERVER array.
Alternatively if you want this information to be in the $_SERVER array, then you will have to use the SetEnv in the virtualhost of your apache information.
How to use the setEnv variable in apache?
$ yii migrate
Yii Migration Tool (based on Yii v2.0.13-dev)
Exception 'yii\db\Exception' with message 'SQLSTATE[HY000] [1049]
Unknown database 'yii''
in E:\laragon\www\website\vendor\yiisoft\yii2\db\Connection.php:586
Stack trace:
#0 E:\laragon\www\website\vendor\yiisoft\yii2\db\Connection.php(932): yii\db\Connection->open()
#1 E:\laragon\www\website\vendor\yiisoft\yii2\db\Connection.php(919): yii\db\Connection->getMasterPdo()
#2 E:\laragon\www\website\vendor\yiisoft\yii2\db\Command.php(219): yii\db\Connection->getSlavePdo()
#3 E:\laragon\www\website\vendor\yiisoft\yii2\db\Command.php(1031): yii\db\Command->prepare(true)
#4 E:\laragon\www\website\vendor\yiisoft\yii2\db\Command.php(362): yii\db\Command->queryInternal('fetchAll', NULL)
#5 E:\laragon\www\website\vendor\yiisoft\yii2\db\mysql\Schema.php(320): yii\db\Command->queryAll()
#6 E:\laragon\www\website\vendor\yiisoft\yii2\db\mysql\Schema.php(111): yii\db\mysql\Schema->findColumns(Object(yii\db\TableSchema))
#7 E:\laragon\www\website\vendor\yiisoft\yii2\db\Schema.php(661): yii\db\mysql\Schema->loadTableSchema('migration')
#8 E:\laragon\www\website\vendor\yiisoft\yii2\db\Schema.php(174): yii\db\Schema->getTableMetadata('{{%migration}}', 'schema', true)
#9 E:\laragon\www\website\vendor\yiisoft\yii2\console\controllers\MigrateController.php(201): yii\db\Schema->getTableSchema('{{%migration}}', true)
#10 E:\laragon\www\website\vendor\yiisoft\yii2\console\controllers\BaseMigrateController.php(864): yii\console\controllers\MigrateController->getMigrationHistory(NULL)
#11 E:\laragon\www\website\vendor\yiisoft\yii2\console\controllers\BaseMigrateController.php(166): yii\console\controllers\BaseMigrateController->getNewMigrations()
#12 [internal function]: yii\console\controllers\BaseMigrateController->actionUp(0)
#13 E:\laragon\www\website\vendor\yiisoft\yii2\base\InlineAction.php(57): call_user_func_array(Array, Array)
#14 E:\laragon\www\website\vendor\yiisoft\yii2\base\Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#15 E:\laragon\www\website\vendor\yiisoft\yii2\console\Controller.php(135): yii\base\Controller->runAction('', Array)
#16 E:\laragon\www\website\vendor\yiisoft\yii2\base\Module.php(528): yii\console\Controller->runAction('', Array)
#17 E:\laragon\www\website\vendor\yiisoft\yii2\console\Application.php(180): yii\base\Module->runAction('migrate', Array)
#18 E:\laragon\www\website\vendor\yiisoft\yii2\console\Application.php(147): yii\console\Application->runAction('migrate', Array)
#19 E:\laragon\www\website\vendor\yiisoft\yii2\base\Application.php(386): yii\console\Application->handleRequest(Object(yii\console\Request))
#20 E:\laragon\www\website\yii(20): yii\base\Application->run()
#21 {main}
this my db
return [
'class' => 'yii\db\Connection', 'driverName' => 'mysql',
'dsn' => 'mysql:host=localhost;dbname=yii',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
// Schema cache options (for production environment)
//'enableSchemaCache' => true,
//'schemaCacheDuration' => 60,
//'schemaCache' => 'cache', ];
The error message means you need to create a database name 'yii'.
Just use Menu > MySQL > Create database to create the database.
I am trying to run a local copy of my website but everytime I run it gives me this error. I tried to look after other similar answer but could not find a relevant answer.
I am using Macbook, XAMPP and Magento 1.8
This is the error displayed
Invalid backend name []
Trace:
#0 /Applications/XAMPP/xamppfiles/htdocs/ameb_prod/lib/Zend/Cache.php(137): Zend_Cache::throwException('Invalid backend...')
#1 /Applications/XAMPP/xamppfiles/htdocs/ameb_prod/lib/Zend/Cache/Backend/TwoLevels.php(135): Zend_Cache::_makeBackend('', Array, true, true)
#2 /Applications/XAMPP/xamppfiles/htdocs/ameb_prod/lib/Zend/Cache.php(153): Zend_Cache_Backend_TwoLevels->__construct(Array)
#3 /Applications/XAMPP/xamppfiles/htdocs/ameb_prod/lib/Zend/Cache.php(94): Zend_Cache::_makeBackend('TwoLevels', Array, true, true)
#4 /Applications/XAMPP/xamppfiles/htdocs/ameb_prod/app/code/core/Mage/Core/Model/Cache.php(137): Zend_Cache::factory('Varien_Cache_Co...', 'TwoLevels', Array, Array, true, true, true)
#5 /Applications/XAMPP/xamppfiles/htdocs/ameb_prod/app/code/core/Mage/Core/Model/Config.php(1354): Mage_Core_Model_Cache->__construct(Array)
#6 /Applications/XAMPP/xamppfiles/htdocs/ameb_prod/app/Mage.php(463): Mage_Core_Model_Config->getModelInstance('core/cache', Array)
#7 /Applications/XAMPP/xamppfiles/htdocs/ameb_prod/app/code/core/Mage/Core/Model/App.php(401): Mage::getModel('core/cache', Array)
#8 /Applications/XAMPP/xamppfiles/htdocs/ameb_prod/app/code/core/Mage/Core/Model/App.php(295): Mage_Core_Model_App->_initCache(Array)
#9 /Applications/XAMPP/xamppfiles/htdocs/ameb_prod/app/code/core/Mage/Core/Model/App.php(337): Mage_Core_Model_App->baseInit(Array)
#10 /Applications/XAMPP/xamppfiles/htdocs/ameb_prod/app/Mage.php(684): Mage_Core_Model_App->run(Array)
#11 /Applications/XAMPP/xamppfiles/htdocs/ameb_prod/index.php(87): Mage::run('', 'store')
#12 {main}
I try install Impresspages on my hosting but after installation have:
Fatal error: Uncaught exception 'Ip\Exception\View' with message 'View view/widget.php not found.' in /Ip/Functions.php:887 Stack trace: #0 /Ip/Internal/Content/Model.php(272): ipView('view/widget.php', Array) #1 /Ip/Internal/Content/Model.php(35): Ip\Internal\Content\Model::_generateWidgetPreview(Array, false) #2 /Ip/Internal/Content/PublicController.php(17): Ip\Internal\Content\Model::generateBlock('main', '13', 0, false) #3 [internal function]: Ip\Internal\Content\PublicController->index() #4 /Ip/Internal/Core/Job.php(126): call_user_func_array(Array, Array) #5 [internal function]: Ip\Internal\Core\Job::ipExecuteController_70(Array) #6 /Ip/Internal/Dispatcher/JobDispatcher.php(39): call_user_func('\Ip\Internal\Co...', Array) #7 /Ip/Dispatcher.php(101): Ip\Internal\Dispatcher\JobDispatcher->handle('ipExecuteContro...', Array) #8 /Ip/Functions.php(368): Ip\Dispatcher->job('ipExecuteContro...', Array) #9 /Ip/Application.php(301): ipJob('ipExecuteContro...', Array) #10 /Ip/Application.php(319): Ip\Application->_handleOnlyR in /Ip/Functions.php on line 887
Where is the problem?
The only thing I could think of right now is that file upload to the server has failed. Try reupload Ip folder.
Thank you.
Problem solved.
The problem was in the server settings.