I have Http server running on my PC, I can use localhost or 192.168.1.69 talk to the server.
I have a tablet in the same wifi as the PC, when I do 192.168.1.69:8080/hello
I don't get any response.
I tried set up port forwarding on router, added .exe to firewall trust, also tried use public ip(that open router login page) with port number. but they doesn't help,
public HttpServer(int port)
{
if (!HttpListener.IsSupported)
{
// Requires at least a Windows XP with Service Pack 2
throw new NotSupportedException(
"The Http Server cannot run on this operating system.");
} // end if HttpListener is not supported
_httpListener = new HttpListener();
_httpListener.Prefixes.Add("http://localhost:" + port + "/");
_httpListener.Prefixes.Add("http://192.168.1.69:" + port + "/");
_resourceLocator = new Locator();
}
public void Start()
{
if (!_httpListener.IsListening)
{
_httpListener.Start();
_running = true;
_connectionThread = new Thread(new ThreadStart(this.ConnectionThreadStart));
_connectionThread.Start();
}
}
Related
I'm working on windows service that uploads files to sftp server using SSH.NET. Problem is when I run code responsible for sending file from windows console app everything works fine, but when exact the same code is running from windows service i recive exception when connecting to SFTP : "A connection can not be made because the target computer actively refuses it"
I have SFTP server running on the same machine for testing.
public void Send(string host, string userName, int port, string password, string filePath)
{
var connectionInfo = new ConnectionInfo(host, userName, new PasswordAuthenticationMethod(userName, password));
try
{
var sftpClient = new SftpClient(connectionInfo);
sftpClient.Connect(); // exception occurs there
using (FileStream fileStream = File.OpenRead(filePath))
{
sftpClient.UploadFile(fileStream, $"{Path.GetFileName(filePath)}", true);
}
sftpClient.Disconnect();
sftpClient.Dispose();
}
catch (Exception exception)
{
Logger.Log($"{host} | {password} | {port} | {userName}");
Logger.Log(exception.Message);
Logger.Log(exception.StackTrace);
}
}
Does anyone have an idea what is going on? I think that can be some configuration problem because like I said the same code runs fine from console app.
I have to check remote IP and Port is available or not.If its is available it will move to next form.If not available it should come to the initial state.I tried using this
while (true)
{
IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties();
IPEndPoint[] ipEndPoints = ipProperties.GetActiveTcpListeners();
-------
-------
-------
}
I am showing the example coding.it was checking local IP and port and moving to next form.it will check local port and IP is available.if port and IP not available it will come to the initial stage and it was working fine.same thing i have to check in remote Port and IP.
Use the Ping class of .NET to find out if the system is up and connected, the use the PortScanner to check if the port is open. check these links for further reading and exploring.
http://msdn.microsoft.com/en-us/library/system.net.networkinformation.ping%28v=vs.110%29.aspx
http://social.msdn.microsoft.com/Forums/vstudio/en-US/8e4410bd-307f-4264-9575-cd9882653945/help-with-portscanner-in-c?forum=csharpgeneral
OR
public static bool PingHost(string hostUri, int portNumber)
{
try
{
using (var client = new TcpClient(hostUri, portNumber))
return true;
}
catch (SocketException ex)
{
MessageBox.Show("Error pinging host:'" + hostUri + ":" + portNumber.ToString() + "'");
return false;
}
}
I have developed a OWIN self host webApi application with angularjs 1.6 and c# .net. Am able to access my application on my LOCAL LAN network but unfortunately i lack in knowledge of setting it up a 'self hosted webApi' application over internet and am struggling it to work on internet. Am looking for some assistance.
`
static void Main()
{
bool first = false;
m = new Mutex(true, Application.ProductName.ToString(), out first);
if ((first))
{
// Specify the URI to use for the local host:
string baseUri = "http://*:8757";
Console.WriteLine("Starting web Server...");
WebApp.Start<Startup>(baseUri);
//MessageBox.Show("Server running at {0} - press Enter to quit. ", baseUri);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainWindow());
}
else
{
MessageBox.Show(" Cannot start another instance of server !!!!!!!" + " ." + " " + "Server is running........");
}
}
`
I'm using AxInterop.MSTSCLib.dll in my app to remote to my server
the code is common like below:
var rdp = new AxMSTSCLib.AxMsRdpClient6NotSafeForScripting();
rdp.Server = "ServerAddress";
rdp.UserName = "Username";
sec.ClearTextPassword = "password";
rdp.Connect();
now i want to remote as UDP protocol
the server pc is ready for udp remote(udp components installed) and i tested it by Remote Desktop
but what i do in my app and code to remote to server as UDP enabled?
depending on this answer , you need to use this code to enable the remote desktop if i understand you well this code what you need
try
{
RegistryKey key = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, TargetMachine.Name);
key = key.OpenSubKey(#"SYSTEM\CurrentControlSet\Control\Terminal Server", true);
object val = key.GetValue("fDenyTSConnections");
bool state = (int)val != 0;
if (state)
{
key.SetValue("fDenyTSConnections", 0, RegistryValueKind.DWord);
MessageBox.Show("Remote Desktop is now ENABLED");
}
else
{
key.SetValue("fDenyTSConnections", 1, RegistryValueKind.DWord);
MessageBox.Show("Remote Desktop is now DISABLED");
}
key.Flush();
if (key != null)
key.Close();
}
catch
{
MessageBox.Show("Error toggling Remote Desktop permissions");
}
I have to check remote IP and Port is available or not.If its is available it will move to next form.If not available it should come to the initial state.I tried using this
while (true)
{
IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties();
IPEndPoint[] ipEndPoints = ipProperties.GetActiveTcpListeners();
-------
-------
-------
}
I am showing the example coding.it was checking local IP and port and moving to next form.it will check local port and IP is available.if port and IP not available it will come to the initial stage and it was working fine.same thing i have to check in remote Port and IP.
Use the Ping class of .NET to find out if the system is up and connected, the use the PortScanner to check if the port is open. check these links for further reading and exploring.
http://msdn.microsoft.com/en-us/library/system.net.networkinformation.ping%28v=vs.110%29.aspx
http://social.msdn.microsoft.com/Forums/vstudio/en-US/8e4410bd-307f-4264-9575-cd9882653945/help-with-portscanner-in-c?forum=csharpgeneral
OR
public static bool PingHost(string hostUri, int portNumber)
{
try
{
using (var client = new TcpClient(hostUri, portNumber))
return true;
}
catch (SocketException ex)
{
MessageBox.Show("Error pinging host:'" + hostUri + ":" + portNumber.ToString() + "'");
return false;
}
}