Starting multiple HTTP listeners on IIS using C#.NET 2.0 - exception

I have two windows services running on the same machine. Both the services uses
private HttpListener listener;
I specify the baseURL as "http://IPAddress:8080/" & "http://IPAddress:8081/" respectively for each of the services. Then I do the needful and call
listener.Start();
The first service starts successfully at 8080 port. But when I now start the 2nd service,
I get HTTPListenerException "The process cannot access the file because it is being used by another process" for listener object.
Could anybody please tell me:
1) If it is possible to start two HTTP listeners on the same IIS at two different ports.
2) If yes, how can we achecive this?
3) Is there any other way of doing this?
For your information:
I am using C#.NET 2.0 and IIS 6.0 server.
Thanks & Regards,
Hari

Doesn't HttpListener work independently from IIS? Can you stop the IIS service and see what happens?
Or maybe port 8081 is used by another program or process. I suggest to try to set the port to another number. You could open a command line and execute the "netstat" command to see if the port is used before starting your services.
(source: googlepages.com)

The HTTPListener is indeed not a part of the IIS. It's just C# code.
did you do it like this?
String[] prefixes = { "http://localhost:8280/", "http://localhost:8281/"};
HttpListener listener = new HttpListener();
listener.Prefixes.Add("http://localhost:8280/");
listener.Start();
1) If it is possible to start two HTTP listeners on the same IIS at two different ports.
Yes, it is. But listeners on the IIS is not made through code, it's through the IIS administration tool, so that's probably not what you're trying to do. IIS is separate from the c# code you're attempting.
2) If yes, how can we achecive this?
Try some other port numbers (like 58080 and 58081) and try replacing "IPAddress" with "localhost". Most likely your port number is used by some other web server
3) Is there any other way of doing this?
If you're trying to serve web pages, you probably wan't to make a web application instead of making your own HTTP server
If you're doing something custom, you might want to take a look at WCF (Windows Communication Foundation), as it's the new framework for web, sockets, web services etc. and it's what MS will be using going forward

It's usually a good idea to take a quick look at this page when using port numbers...just to make sure a temp number you're trying to use isn't in use already.

Related

In a in WinRT app, how do I connect using TLS1.2?

I've got a Windows Store app that's a WinRT Phone/Desktop app (i.e. not a UWP app), targeting Windows 8.1 and up.
It's been on the store for several years now, but recently it stopped being able to connect with various web APIs and websites (YouTube, as well as my own site) using HTTPS.
I have a WPF version of this app as well, and this happened on that app recently as well, and to fix it I used System.Net.ServicePointManager. Unfortunately, in my WinRT environment, System.Net doesn't include ServicePointManager. In my WPF app, I did this, and it worked just fine:
ServicePointManager.ServerCertificateValidationCallback = delegate
{
Debug.WriteLine("returning true (the ssl is valid)");
return true;
};
// our server is using TLS 1.2
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
In doing some research around the internet, it seems that .NET 4.6 should include ServicePointManager, but I don't see any way to change (or even see) my version of .NET in the WinRT development environment.
I looked some more and found that a StreamSocket could be used to connect with TLS1.2... but that seems primarily designed to enable bluetooth communications, or communications to a web endpoint, but only by hostname... which is insufficient for me. I need to connect to an actual website, not just the base-level domain.
Trying this, I did the following:
StreamSocket socket = new StreamSocket();
string serverServiceName = "https";
socket.Control.KeepAlive = false;
url = "inadaydevelopment.com";
HostName serverHost = new HostName(url);
await socket.ConnectAsync(serverHost, serverServiceName, SocketProtectionLevel.Tls12);
text = await ReadDataFromSocket(socket);
I can include the code for ReadDataFromSocket() if necessary, but it seems to work, reading the data from the socket as expected when I point it at https://google.com. However, I can't seem to figure out how to point the socket at anything useful. The homepage of inadaydevelopment.com isn't what I want; I'm looking to consume a web API hosted on that server, but can't seem to find a way to do that.
Since the first parameter to the ConnectAsync() method is just HostName, the second parameter (remoteServiceName) must be the way to connect to the actual API or webpage I'm trying to connect to. According to the docs, that is The service name or TCP port number of the remote network destination... I haven't seen any example values for this parameter other than https and various numeric values, neither of which is going to get me to the API endpoint or webpage I'm trying to connect to.
So, with that super-long preamble out of the way, my question boils down to this:
Is there a way for me to use System.Net.ServicePointManager in my WinRT app like I do in my WPF app? If so, how?
If not, how can I use StreamSocket to connect to the exact web service or webpage I want to connect to, rather than just the top-level host?
If that's not possible, by what other means can I consume web content using TLS1.2?
Thanks in advance for any help or advice.
Use Windows.Web.Http API instead of System.Net.Http API.
System.Net.Http does not support TLS1.2 but Windows.Web.Http does in WinRT apps.

Scout Eclipse ScoutServerTestRunner on client tests

now I run on new problems with scout testing.
I have Client fragment project for testing and I would like to test some templates I created.
My problem is that this templates contains some SmartFields and I would like to test them. For this I probably need ScoutServerTestRunner, so the server is up and running.
But If I try to add it I get error :
#RunWith(ScoutServerTestRunner.class)
#ServerTest()
I get error :
ServerTest cannot be resolved to a type
, all of my assert imports are deleted and I get error on my package line suggesting me Configure build path.
My guess is that this can't be done because it is client fragment and it can't connect to server.
But how then test smartFields ?
From your question I guess that there is some misunderstanding...
ScoutServerTestRunner and #ServerTest is something similar to ClientServerTestRunner and #ClientTest but for the server. You will need it for tests testing the server.
The classes are located in the org.eclipse.scout.rt.testing.server bundle.
If in a client test you need a server you have two possibilities:
A/ Start a server
You can start a server
This will probably not be the normal server (the one like in production) because you want to control the database or some external services. Authentication might also be slightly different (in order to control it and to have something compatible with your tests)
For the integration in your maven build, the maven-cargo plugin can be used to start your server before executing the client test suite.
B/ Mock the server services
Each of the services call that creates a ProxyService calling the server, can be replaced by mock (client only).
This is the preferred way for unit test, because you do not rely on a deployed server. You can also define for each test what the server answer will be.
This solutions requires probably initially more work, but in my opinion it worth it.
To register an alternative service, you can use:
TestingUtility.registerServices(
<activator instance>,
<priority>,
<service instances>
);
The service with the higher priority will win.
In each test, do not forget to un-register the alternative services you have registered.
SmartFields are using CodeTypes or LookupCalls. In case of a LookupCall, the LookupCall is probably calling the server through a LookupService. In case of a CodeType, the SmartField is internally using the CodeLookupCall class relying on a ICodeService.
In both cases, if you want to run your test without a server, you need to ensure that the client uses alternative implementations of the required services that do requires a server.

Can I use "new ServerSocket(0)" with openshift

I have developed an application that allows multiple players to play together on line at various games such shifumi, poker, chess and so on. It works very well on my localhost. I would like to publish it. So I decided to use openshift to do this.
But there is a problem.
It seems it come from this statement : new ServerSocket(0). I do this inside the doPost method of an HttpServlet.
Could you tell me I don't have the permission to do this (new ServerSocket(0)) inside an openshift server?
I think you have a couple of issues going on here.
The first is that when you call new ServerSocket(0), it is going to try to find a socket that it can bind to, probably on either 0.0.0.0 (all ip addresses/interfaces) or 127.0.0.1, neither of which is allowed on OpenShift.
According to the documentation (located here: http://download.java.net/jdk7/archive/b123/docs/api/java/net/ServerSocket.html) you can use one of the overloaded methods to provide an ip address to bind to, which should be your OPENSHIFT__IP (where could be jbosseap, jbossas, wildfly, jbossews, etc).
ServerSocket(int port, int backlog, InetAddress bindAddr)
Your second issue is a bit more complicated, basically what ports you can bind to. OpenShift allows user code to bind to ports 15000-20000, depending on what ports are not being used by other applications or services. However, none of those ports are open to the public internet, they are all internal ports for internal communications, so if you are trying to let a client connect to them, it won't work. The only ports that are publicly available are 80/443/8000/8443, and your application must bind to port 8080 on your OPENSHIFT__IP to be able to be reached using your app-domain.rhcloud.com public url. You can check out this article to read more about how all of the binding and routing works: https://developers.openshift.com/en/managing-port-binding-routing.html
Hopefully that answers the question about why that piece of code is not working.

What is the url for Couchbase UI?

I used couchdb before and really liked the UI, because I can create views and test them directly in UI and view documents.
Because, I need to scale, I started using couchbase. But, after installing couchbase, I don't know the url of couch base client side UI.
Thank you
Just use public IP of any of the nodes in the cluster and connect to port 8091, like this http://example.com:8091
Yes it's served via 8091. But I would read through this section of the docs: http://www.couchbase.com/docs/couchbase-manual-2.0/couchbase-bestpractice-cloud-ip.html; when it comes to IP's.
//Daniel
CouchDB's GUI is available at http://127.0.0.1:5984/_utils

Adobe AIR, URLRequest, and local ports

I'm looking at writing an app with Adobe AIR, but I wanted to figure out if this is feasible with the platform first. (Mostly new to Flash and AIR)
What I would like to do is know ahead of time what local port a URLRequest will be using. If possible, I would like to hold a connection open even and keep using the same socket.
What I'm basically trying to accomplish is doing some NAT-Traversal and port negotiation ahead of time. Once I have both the client and the server negotiated, I'd like them to connect and basically use HTTP in a peer-to-peer way to stream media, like this sample:
var s = new air.Sound();
var url = "http://www.example.com/sounds/bigSound.mp3";
var req = new air.URLRequest(url);
var context = new air.SoundLoaderContext(8000, true);
s.load(req, context);
s.play();
The problem is that I don't see this happening unless I can get some information from AIR on what ports it's planning to use. I would be OK with creating my own Socket connections to the server and using them, but I would need a way to leverage the Sound framework to stream in the same way from a socket.
Ideas? Thoughts? Thanks!
Even if you managed to guess which port AIR is going to use on your device, it is not going to be very helpful, since there is a reasonably high probability that your NAT will translate it to another value IF your AIR device has a private IP address.
This issue does not happen if your AIR server has a public IP address. Most often, you can configure the server's NAT/Router to forward traffic as is. A port scan from the WAN will quickly tell you which port is used.
If you want to 'hijack' an outbound connection created by AIR itself, then you might try to have it contact a special server peer you have implemented which will forward traffic from and to it. Not simple, but possible. Basically you would collect holes punched in the NAT by the server.