How to connect to Mosquitto by using react-websocket - reactjs

After npm install react-websocket
I'm trying to connect Windows Mosquitto(MQTT Broker server).
and then I set the websocket address in my react source, but cannot receive messages from Mosquitto, and also cannot publish any messages to Mosquitto server.
But it works in glassfish server which is run by Java.
I think Mosquitto and glassfish server are same websocket server, but it seems to be that there is difference between them.
Is there solution to connect Mosquitto Broker server by using react-websocket library?
react-websocket library's version is 2.0.0
Mosquitto MQTT Broker server version is 1.5.4
import Websocket from 'react-websocket'
export default class WebsocketInput {
constructor(queue, onOpenCallback) {
this.queue = queue
this.websocket = new Websocket({
url: process.env.REACT_APP_WEBSOCKET_ADDRESS,
onMessage: function(data) {
queue.offer(JSON.parse(data))
},
onOpen: function() {
onOpenCallback()
}
})
this.websocket.setupWebsocket()
}
sendMessage(msg) {
this.websocket.state.ws.send(msg)
}
close() {
this.websocket.shouldReconnect = false
this.websocket.state.ws.close()
}
}
Here is React code and I downloaded this from https://github.com/door2door-io/simulation-demo. I set the url 'ws://localhost:9001', but can't receive any messages in React app.
port 1883
protocol mqtt
listener 9001
protocol websockets
And this is part of mosquitto.conf file. I run the server by typing mosquitto -v -c mosquitto.conf, and I run mosquitto server in Windows CMD.
thanks

Related

call revert exception in using ether.js

i am setting up react with ether.js and smart contract is deployed using hardhat on localhost network. React app is connected to metasmask using
const provider = new ethers.providers.Web3Provider(window.ethereum);
the contract is written below
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;
import "hardhat/console.sol";
contract Greeter {
string private greeting;
constructor(string memory _greeting) {
console.log("Deploying a Greeter with greeting:", _greeting);
greeting = _greeting;
}
function greet() public view returns (string memory) {
return greeting;
}
function setGreeting(string memory _greeting) public {
console.log("Changing greeting from '%s' to '%s'", greeting, _greeting);
greeting = _greeting;
}
}
i deployed this contract using npx hardhat run script.js.In the react code i am fetching contract object using
const erc20=new ethers.Contract(address,obj.abi,signer);
and in the useEffect i am trying to call erc20.greet()
which is giving error in console.
**
(in promise) Error: call revert exception (method="greet()", errorArgs=null, errorName=null, errorSignature=null, reason=null, code=CALL_EXCEPTION, version=abi/5.5.0)
**
You need to make sure these points:
Your Metamask extension is connecting to your hardhat localhost network.
When you run your React app in a browser with the Metamask extension installed, make sure that your Metamask is connecting to your hardhat localhost network (by default, it is localhost:8545). If Metamask is connecting to a different network, you will get that error.
(Note: Because the Metamask extension hides test networks by default, you will need to make it show test networks so that you can see your hardhat localhost network listed.)
Use the correct contract address.
When you start a hardhat local network, hardhat will return a list of accounts like this:
WARNING: These accounts, and their private keys, are publicly known. Any funds sent to them on Mainnet or any other live network WILL BE LOST.
Account #0: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 (10000 ETH)
Private Key: 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
Account #1: 0x70997970c51812dc3a010c7d01b50e0d17dc79c8 (10000 ETH)
Private Key: 0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d
...
When you deployed that smart contract using hardhat on localhost network, hardhat will return something like this:
[contract-name] deployed to: [contract-address]
Make sure that you use that [contract-address] as the value of the address argument here:
const erc20=new ethers.Contract(address,obj.abi,signer);
A [contract-address] and an account look quite similar, but they represent two different things. If you use an account instead the [contract-address], you will get the error.

Can I use AWS Device Farm with WebdriverIO Mobile testing?

I have a webdriverIO framework built. I am trying to setup a webdriverIO config file to connect to AWS Device Farm, and obtaining a mobile device, then running the appium based tests.
Maybe something like this? for the config file for iOS?
But the issue I have is the following:
How do I point to the IPA file that I have uploaded to the server?
How do I connect to the AWS Device Farm?
Is it safe to assume since AWS Device Farm runs an appium server, the supported capabilities is what I should use from appium?
const { join } = require('path');
const { config } = require('./wdio.conf');
config.specs = [
'./tests/specs/**/*.spec.js',
];
config.capabilities = [
{
platformName: 'iOS',
maxInstances: 1,
'appium:deviceName': 'iPhone 12',
'appium:platformVersion': '14.4',
'appium:orientation': 'PORTRAIT',
'appium:automationName': 'XCUITest',
'appium:app': 'replace this with your locally built app - full path to app file',
// 'appium:app': join(process.cwd(), './apps/iOS-Simulator-NativeDemoApp-0.2.1.app.zip'),
'appium:noReset': true,
'appium:newCommandTimeout': 240,
},
];
exports.config = config;
For these questions:
How do I point to the IPA file that I have uploaded to the server?
AWS Device Farm uses a server-side execution platform, where you upload your app and test code using the CreateUpload API (ref https://docs.aws.amazon.com/devicefarm/latest/APIReference/API_CreateUpload.html).
How do I connect to the AWS Device Farm?
You do not connect to AWS Device Farm from your local client, you Schedule a run on Device Farm using the ScheduleRun API (ref https://docs.aws.amazon.com/devicefarm/latest/APIReference/API_ScheduleRun.html)
Is it safe to assume since AWS Device Farm runs an appium server, the supported capabilities is what I should use from appium?
Yes, Device Farm executes your test on a server-side platform using an Appium server at localhost:4723
Please see this blog post for a detailed walk-through that should clarify some of these things for you: https://aws.amazon.com/blogs/mobile/testing-mobile-apps-with-cucumber-and-appium-through-testng-on-aws-device-farm/

How to connect GCP Cloud Run Java Spring to Cloud SQL SQL Server

I have a little problem, I want to deploy a Java Spring App to Cloud RUN and take connection from CLOUD SQL SQL SERVER , I know that can connect via unix socket for MySQL and Postgresql (https://cloud.google.com/sql/docs/mysql/connect-run?hl=es-419) but for SQL Server do not has the drivers jet.
Another way is to connect for Proxy Like (https://medium.com/#petomalina/connecting-to-cloud-sql-from-cloud-run-dcff2e20152a)
I tried but I can't, even that when deploy the script, it's tell me that is listenning for 127.0.0.1 for my instance id but when a tried to connect I can't.
here is my docker file
# Use the official maven/Java 8 image to create a build artifact.
# https://hub.docker.com/_/maven
FROM maven:3.5-jdk-8-alpine as builder
# Copy local code to the container image.
WORKDIR /app
COPY pom.xml .
COPY src ./src
COPY ohJpo-2.1.0.jar .
# download the cloudsql proxy binary
# RUN wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 -O ./build/cloud_sql_proxy
# RUN chmod +x ./build/cloud_sql_proxy
COPY cloud_sql_proxy /build/cloud_sql_proxy
RUN chmod +x /build/cloud_sql_proxy
# copy the wrapper script and credentials
COPY run.sh /build/run.sh
COPY credentials.json /build/credentials.json
# Build a release artifact.
RUN mvn install:install-file -Dfile=/app/ohJpo-2.1.0.jar -DgroupId=ovenfo -DartifactId=ohJpo -Dversion=2.1.0 -Dpackaging=jar
RUN mvn package -DskipTests
# Use AdoptOpenJDK for base image.
# It's important to use OpenJDK 8u191 or above that has container support enabled.
# https://hub.docker.com/r/adoptopenjdk/openjdk8
# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds
FROM adoptopenjdk/openjdk8:jdk8u202-b08-alpine-slim
RUN /build/cloud_sql_proxy -instances=idInstanceID=tcp:1433 -credential_file=/build/credentials.json & sleep 10
COPY --from=builder /app/target/helloworld-*.jar /helloworld.jar
# Run the web service on container startup.
CMD ["java","-Djava.security.egd=file:/dev/./urandom","-Dserver.port=${PORT}","-jar","/helloworld.jar"]
I my java application I have this way to connect, in local PC with proxy found wit
#GetMapping("/pruebacuatro")
String pruebacuatro() {
Map<String, String> config = new HashMap<String, String>();
config.put("type", "SQLSERVER");
config.put("url", "127.0.0.1");
config.put("db", "bd");
config.put("username", "user");
config.put("password", "pass");
Object data = null;
Jpo miJpo = null;
try {
miJpo = new Jpo(config);
Procedure store = miJpo.procedure("seg.menu_configuraciones");
data = store.ejecutar();
} catch (Exception e) {
e.printStackTrace();
} finally {
if(miJpo != null) {
try {
miJpo.finalizar();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return "Contents json: "+(new Gson().toJson(data));
}
I want to connect with my public IP or Private IP from my SQL Server But also I can't find information about that, Do you have any suggestion?
Cloud SQL proxy work in 2 modes: Unix socket and TCP
When you use it on your computer, you should use the TCP mode and you can connect to it in the localhost IP. However, with Cloud Run, it's the unix socket mode which is used and there isn't SQL server client that can use this connexion mode.
Thus, you have to use the Cloud SQL IP to connect your Cloud SQL instance to your Cloud Run.
For your local tests, continue to use Cloud SQL proxy in TCP mode
For Cloud Run, I recommend you to use the private IP of your SQL server.
Expose your instance in your VPC
Create a serverless VPC connector in the correct region
Attach the Serverless VPC connector to your Cloud Run service
Use the Cloud SQL private IP in your code to connect your DB.

Socket connection getting close while creating room on kurento

I have configure kurento on WS. Its spring boot application running on https://localhost:8443 (tomcat).
Logs:
s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8443 (https)
DEBUG 4730 --- [apterApp.main()] o.s.w.c.s.StandardServletEnvironment : Adding [server.ports] PropertySource with highest search precedence
INFO 4730 --- [apterApp.main()] com.io.AdapterApp : Started AdapterApp in 14.041 seconds (JVM running for 29.346)
Start boot application using below command:
sudo mvn compile exec:java Dkms.url=ws://io-storage:8888/kurento
Websocket running on 8888 port. (not secure WS).
While creating room the request is ws://io-storage:8888/call
But getting following error while request send to the kurento server
2018-10-31 13:12:23,252181 2009 [0x00007fe37ce5b700] error KurentoWebSocketTransport WebSocketTransport.cpp:455 openHandler() Invalid path "/call", closing connection
Kurento Media Server doesn't listen for RPC commands on the /call endpoint. Why are you requesting that URL?
Just use the Java API client by following any of the Java tutorials; this library does all of the RPC commands for you.
If you still need to work without libraries and program directly against the RPC API, then check the protocol docs.

programmatically or CLI to stop webpack-dev-server

How to stop webpack-dev-server programatically of a CLI command against the port ?
Ctrl-C etc are good for manually stopping the server. We are basically killing it.
Is there a API that the server exposes to issue a STOP command or something ?
Just came across this. Hopefully it's still relevant^^
According to documentation, the server can be opened and closed via node api as follows:
// create instance
const server = new WebpackDevServer(webpack(config), { });
// start
server.listen(8000, "localhost", err => {
console.log("server started")
})
// close/stop
server.close(() => {
console.log("server closed")
})
Docs: https://github.com/webpack/docs/wiki/webpack-dev-server

Resources