How to retrieve and connect via public IP Addresses with wxWidgets - wxwidgets

I'm trying to build a very simple chat application with wxWidgets. At the moment, I can open the software on my local machine and on a virtual machine with it's own LAN IP Address. I'm able to retrieve each machines local IP Address via wxGetFullHostName() function; which I then manually enter this value into the other instance so that they connect. Everything works well at this stage.
However, now I'd like to send the .exe to a friend somewhere else. How can I get the application to expose the machines public IP address so that I can provide it to my friend to connect to my instance? Are their any other requirements to have the two instances connect to each other?
I'm using C++, but I don't think it matters much to this question.

For a platform independent method that works behind NAT, I would suggest to use ipify (https://www.ipify.org/).
There are many ways of achieving this in C++ and wxWidgets. Possibly one of the best is to use curl (https://curl.haxx.se/libcurl/).
However, for a 'pure' wxWidgets implementation you can try the following modification to the minimal.cpp sample:
#include <wx/sstream.h>
#include <wx/protocol/http.h>
#include <wx/msgdlg.h>
MyFrame::MyFrame(const wxString& title)
: wxFrame(NULL, wxID_ANY, title)
{
wxHTTP http;
http.SetHeader("Content-type", "text/html; charset=utf-8");
http.SetTimeout(10);
http.Connect("api.ipify.org");
wxInputStream* httpStream = http.GetInputStream("/");
if (http.GetError() == wxPROTO_NOERR)
{
wxString result;
wxStringOutputStream out_stream(&result);
httpStream->Read(out_stream);
wxMessageBox(result);
}
else
{
wxMessageBox("Unable to connect!");
}
wxDELETE(httpStream);
}

Related

Setup BlueZ GATT Server with random address?

I followed GATT_Server example and advertisment example provided in BlueZ and built a GATT server in Python and it works fine.
I wanted to setup GATT server to use Random address instead of public address. adapter-api and device-api has AddressType field but it is read-only and I can't change it to Random.
Is it possible to setup BlueZ GATT server with Random address?
I think I was having a similar problem. Here's how I solved my problem:
After a lot of searching, I found that PyBluez just uses gattlib for all ble stuff: documentation
I was able to connect to my device with the following: (python 2.7)
import gattlib
requester = gattlib.GATTRequester('EF:76:B5:CC:36:A0', False)
reqer.connect(True, channel_type='random')
I know it's not the same as your problem, but I'm hoping it might help anyways.

'Address already in use' when running tests using Spring LDAP embedded server

I am trying to use Spring LDAP in one of my Spring Boot projects but I am getting an 'Address already in use' error when running multiple tests.
I have cloned locally the sample project here:
https://spring.io/guides/gs/authenticating-ldap/
...and just added the boilerplate test normally created by Spring Boot to verify that the Application Context loads correctly:
#RunWith(SpringRunner.class)
#SpringBootTest
public class MyApplicationTests {
#Test
public void contextLoads() {
}
}
If run alone, this test passes. As soon as LdapAuthenticationTests and MyApplicationTests are run together, I get the error above for the latter.
After debugging a bit, I've found out that this happens because the system tries to spawn a second instance of the embedded server.
I am sure I am missing something very stupid in the configuration.
How can I fix this problem?
I had a similar problem, and it looks like you had a static port configured (as was in my case).
According to this article:
Spring Boot starts an embedded LDAP server for each application
context. Logically, that means, it starts an embedded LDAP server for
each test class. Practically, this is not always true since Spring
Boot caches and reuses application contexts. However, you should
always expect that there is more than one LDAP server running while
executing your tests. For this reason, you may not declare a port for
your LDAP server. In this way, it will automatically uses a free port.
Otherwise, your tests will fail with “Address already in use”
Thus it might be a better idea not to define spring.ldap.embedded.port at all.
I addressed the same issue. I solved it with an additional TestExecutionListener since you can get the InMemoryDirectoryServer bean.
/**
* #author slemoine
*/
public class LdapExecutionListener implements TestExecutionListener {
#Override
public void afterTestClass(TestContext testContext) {
InMemoryDirectoryServer ldapServer = testContext.getApplicationContext().getBean(InMemoryDirectoryServer.class);
ldapServer.shutDown(true);
}
}
And on each SpringBootTest (or only once in an abstract super class)
#RunWith(SpringRunner.class)
#SpringBootTest
#TestExecutionListeners(listeners = LdapExecutionListener.class,
mergeMode = TestExecutionListeners.MergeMode.MERGE_WITH_DEFAULTS)
public class MyTestClass {
...
}
also do not forget
mergeMode = TestExecutionListeners.MergeMode.MERGE_WITH_DEFAULTS
to avoid disabling the whole #SpringBootTest auto configuration.
Okay, I think I found a solution by adding a #DirtiesContext annotation to my test classes:
#DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
If you are using spring embedded ldap, try to comment or remove port value from config file as below :
spring :
ldap:
embedded:
base-dn: dc=example,dc=org
credential:
username: cn=admin,dc=example,dc=org
password: admin
ldif: classpath:test-schema.ldif
# port: 12345
validation:
enabled: false
Try specifying the web environment type and the base configuration class (the one with !SpringBootApplication on it).
#RunWith(SpringRunner.class)
#SpringBootTest(
classes = MyApplication.class,
webEnvironment = RANDOM_PORT
)
public class MyApplicationTests {
#Test
public void contextLoads() {
}
}
Do this for all your test classes.
I solved this problem by adding #DirtiesContext over each test class that requires embedded ldap server. In my case (and as I feel in many others), embedded ldap server was starting up at every #SpringBootTest, since I added all spring.ldap.embedded.* properties to general application-test.properties. Therefore, when I run a bunch of tests, the problem of 'Address already in use' broke all test passing.
Steps I followed:
create an additional test profile (with corresponding named application properties file, e.g. 'application-ldaptest.properties')
move to that file all spring.ldap.embedded.* properties (with fixed port value)
over all #SpringBootTest-s that do require embedded server running up, add #ActiveProfiles("testladp") and #DirtiesContext annotations.
Hope, that helps.

Non local IP-ADDRESS in izpack

I'm trying get the IP address in my izpack installer. I have used the ${IP_ADDRESS} variable, but I get the local "127.0.0.1" address instead of the public IP of the computer. Is it the expected functioning? It seems quite useless to me, but I must have missed something. How can I get the public IP?
izpack: v5.0.3
java: 1.7.0_79
Ubuntu: 15.04
Thanks.
It looks like, ${IP_ADDRESS} is taken as (part from IzPack installer sources):
InetAddress localHost = InetAddress.getLocalHost();
IPAddress = localHost.getHostAddress();
hostname = localHost.getHostName();
So, the problem is, that InetAddress.getLocalHost() in most cases returns localhost addresses.
If you need to determine your public ip, it's not as easy, as just to take your localhost's address. You have to iterate over your network interfaces, getting their addresses and determine, which one you need. It's quite a common case if you need to do it not in your business code, but you need it inside the installer.
As I know, it's possible to make your own jar-file and to use it inside your installer, may be you should try to make your own ligic, that determine this public ip and is called from your IzPack installer.

Setting up XSockets on Windows Server 2003 R2, IIS6

I am looking for some guidance on setting up an MVC/XSockets project on our servers running Windows Server 2003, R2 with IIS6.
Our team is developing a webapp that uses XSockets 3.x to dynamically display data in real time. We are using our time entry system to show current time entries on a "dashboard." Employees enter their times via a separate app, and the dashboard app is supposed to show most recent activity updates.
The project is made using the MVC4 framework. This works great when testing from my development machine, separate from the server. The ws server instance is setup on ws://x.x.x.x:4502, where x.x.x.x is the server's IP. The XSockets components are integrated in the same project.
After pushing my local project onto the server and doing some setup, everything works okay except the XSockets functionality. The XSockets server cannot be accessed from outside the server. When I test from within the server, meaning opening up a browser and going to the webapp, it works fine as it does on my dev machine.
I have tried following the custom configuration setup outlined on xsockets.net, but I am a little confused as to how to define the ws server instance. Do I use the server's IP? The localhost IP (127.0.0.1)? I tried both, but it won't work. I tried adding this custom config settings:
public class XSocketsConfig : ConfigurationSetting
{
public XSocketsConfig() : base(new Uri("ws://dashboard.ourdomain.com:4502/"), new Uri("ws://x.x.x.x:4502")) { }
}
From javascript I access the XSocket through the "ws://dashboard.ourdomain.com:4502/" connection, but it didn't work when I tested it after deploying to the server. I also tried:
public class XSocketsConfig : ConfigurationSetting
{
public XSocketsConfig() : base(new Uri("ws://x.x.x.x:4502")) { }
}
or
public class XSocketsConfig : ConfigurationSetting
{
public XSocketsConfig() : base(new Uri("ws://127.0.0.1:4502")) { }
}
I did enable the server firewall to let traffic through port 4502. Again, everything works great on my local machine, so this leaves me to believe it is either a setting on the server, or a config setting for XSockets.
What is the proper way of achieving a client-server connection on IIS 6? Pointers and suggestions are greatly appreciated as my several-day search has yielded no effective results yet.
Okay so I have finally figured it out. It was after all a firewall issue. I had to configure the firewall to allow traffic on the public ip and port and to forward that traffic to the private ip and port. My XSockets configuration ended up looking like this:
//http://xsockets.net/docs/configuration#public--private-endpoint
public class XSocketsConfig : ConfigurationSetting
{
public XSocketsConfig() : base(new Uri("ws://x.x.x.x:4502/"), new Uri("ws://y.y.y.y:4502")) { }
}
Where x.x.x.x is the server's public IP address and y.y.y.y the private IP address on the LAN. On the client side (js) I then do:
var conn = new XSockets.WebSocket('ws://x.x.x.x:4502/Activity');
That took a serious amount of troubleshooting but I am glad I got it figured out.

Flex 4 - Technique to allow HTTPService testing locally and on development server

Right now I have my URLs hard-coded for HTTPService to work with my local machine's web server so that I don't need to copy files to htdocs after compiling. What's a good technique to easily transition HTTPService URLs from working on my testing setup to working with a normal web server setup?
Write a service to get the current environment your application is in, similar to how one tests if you're running in AIR or Flex.
In your HTTPService:
url="EnvironmentService.getURL1();"
In EnvironmentService:
public static function getUrl1():URL
{
return (LOCAL_ENVIRONMENT)? LOCAL_URL1 : LIVE_URL1;
}
If this doesn't work for you, post some more code and we'll work on a solution