Im using http://managedupnp.codeplex.com/ API to open up a port using UPNP on my NetGear DG834g ROUTER with the following code..
public void UPNPOpenPort(int port)
{
Services lsServices;
lsServices = Discovery.FindServices("urn:schemas-upnp-org:service:WANPPPConnection:1");
if (lsServices.Count > 0)
using (Service lsService = lsServices[0])
{
try
{
object[] loObj = new object[] { "", port, "TCP", port, "10.0.0.100", true, "Custom Mapping", 0 };
lsService.InvokeAction("AddPortMapping", loObj);
}
catch (Exception loE)
{
MessageBox.Show(
String.Format(
"{0}: HTTPSTATUS: {1}",
loE.Message,
lsService.LastTransportStatus));
}
}
else
{
MessageBox.Show("Doh No Router Found");
return;
}
}
I have a service host with a NetTCP binding with the same port im feeding into the sub routine to set the UPNP forwarding and I can see an active UPNP record on the router configuration. I can see the port is listening on my local machine and other PC's on my LAN can connect to the port however using an online Port checker it shows as closed, even though the Router says that it should be forwarding to the correct internal IP.
Does anyone have any ideas or am i missing something?
Best Regards,
Christopher Leach
Yes. I performed a factory restore on the router, enabled UPnP, opened the service host and created a forward. It worked.
Even Teredo decided to come online.
Its great to know from a beginners perspective that its not always your codes(your understanding) fault. Sometimes its your hardware.
Thanks,
Christopher Leach
Related
I am not familiar with AMQP.
I try to connect a AmqpNetLite program to a Qpid server and I get the following exception :
Amqp.AmqpException: sasl-mechanisms(sasl-server-mechanisms:[CRAM-MD5,SCRAM-SHA-1,SCRAM-SHA-256])
Note : I am able to connect to a basic AMQP server, but not QPID.
Here is the code to create the connection:
Please tell where to start to fix my problem.
void Main(string[] args)
{
try
{
Address address = new Address("amqp://guest:guest#localhost:5672");
Connection connection = new Connection(address);
Session session = new Session(connection);
ReceiverLink receiver = new ReceiverLink(session, "receiver-link", "queue");
Message message = receiver.Receive();
receiver.Accept(message);
receiver.Close();
session.Close();
connection.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
Console.ReadLine();
}
The error would seem to indicate that the broker is not able to provide the client with a SASL mechanism that it supports. I think that AmqpNetLite only does ANONYMOUS, PLAIN and EXTERNAL but perhaps that's changed. You could look into your broker configuration and make one of those mechanisms available to the client and that will probably allow for a match and successful authentication. Or you could use an SSL connection which would then allow those SASL mechanisms to work and provide a bit of extra security for you connection.
The security section of the Broker-J documentation site should shed some light on this for you.
i'm trying to build a simple VoIP application using c# so i found that the Ozeki SDK is the simple way to do that but when i'm trying to registration SIP account using the SIPAccount class from the Ozeki SDK and my local IP it fail always and this is the code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ozeki.VoIP;
using Ozeki.VoIP.SDK;
namespace SIP_R
{
class Program
{
private static ISoftPhone softphone; // softphone object
private static IPhoneLine phoneLine; // phoneline object
private static void Main(string[] args)
{
// Create a softphone object with RTP port range 5000-10000
softphone = SoftPhoneFactory.CreateSoftPhone(5000, 10000);
// SIP account registration data, (supplied by your VoIP service provider)
var registrationRequired = true;
var userName = "1000";
var displayName = "1000";
var authenticationId = "1000";
var registerPassword = "1000";
var domainHost = SoftPhoneFactory.GetLocalIP().ToString();
var domainPort = 9000;
var account = new SIPAccount(registrationRequired, displayName, userName, authenticationId, registerPassword, domainHost, domainPort);
// Send SIP regitration request
RegisterAccount(account);
// Prevents the termination of the application
Console.ReadLine();
}
static void RegisterAccount(SIPAccount account)
{
try
{
phoneLine = softphone.CreatePhoneLine(account);
phoneLine.RegistrationStateChanged += sipAccount_RegStateChanged;
softphone.RegisterPhoneLine(phoneLine);
}
catch (Exception ex)
{
Console.WriteLine("Error during SIP registration: " + ex);
}
}
static void sipAccount_RegStateChanged(object sender, RegistrationStateChangedArgs e)
{
if (e.State == RegState.Error || e.State == RegState.NotRegistered)
Console.WriteLine("Registration failed!");
if (e.State == RegState.RegistrationSucceeded)
Console.WriteLine("Registration succeeded - Online!");
}
}
}
so please any help on what to do many thanks in advance for any help..
when trying to make softphone calls using Ozeki SDK and local IP it give an error NatType:UDPBlocked
Do you have both UDP and TCP port 5060 open? (The standard SIP Port)
Can you register a normal SIP softphone from your development machine?
From your error message it sounds like you have a firewall issue, not a code issue.
And looking at your code, I would check all the ports you've entered: 5,000 through 10,000.
After studying your code and the SIP registration explanation at the SDK's website, I think this line generates the problem:
var domainHost = SoftPhoneFactory.GetLocalIP().ToString();
To be able to communicate, we need to register our softphone to a PBX.
To do this, the example uses the Register method. We need to create a
phone line for this registration, which needs a SIP account and a NAT
Traversal method.
(Source: How to register to a PBX using SIP Account?)
So the aim of this code snippet is to define a SIP account that will be registered to a certain PBX. Accordingly, the domainHost should be the IP address of the PBX that you wish to register to. (And the domainPort should be the port number of this PBX.)
Error : NatType:UDPBlocked
SDK code :
<member name="F:Ozeki.Network.Nat.NatType.UdpBlocked">
<summary>
Firewall that blocks UDP.
</summary>
<remarks>
Probably no internet connection available or firewall issue.
</remarks>
</member>
Probably no internet connection available or firewall issue.
Try Enabling advanced outbound NAT, change the default outbound rule to enable static-port. Reboot adapter.
As the SDK code suggests,
Check Firewall and ports you have the issue tackled
I need to get an available IP from the DHCP. I tried to get any ip address and start to ping the next until I reach one that doesn't respond.
public static IPAddress FindNextFree(this IPAddress address)
{
IPAddress workingAddress = address;
Ping pingSender = new Ping();
while (true)
{
byte[] localBytes = workingAddress.GetAddressBytes();
localBytes[3]++;
if (localBytes[3] > 254)
localBytes[3] = 1;
workingAddress = new IPAddress(localBytes);
if (workingAddress.Equals(address))
throw new TimeoutException("Could not find free IP address");
PingReply reply = pingSender.Send(workingAddress, 1000);
if (reply.Status != IPStatus.Success)
{
return workingAddress;
}
}
}
However, sometimes the DHCP reserves special address for some computers, so I need to get an available ip address from the dhcp.
How can I implement that in C#?
That is not the right way you are using it ,
you should request the DHCP server a new ip and then accept it ,
read about communicating with DHCP Server here
http://en.wikipedia.org/wiki/Dynamic_Host_Configuration_Protocol
A client application cannot make a request to the DHCP server for all available addresses.
A DHCP server can only process the following messages from a client:
DHCPDISCOVER
DHCPREQUEST
DHCPDECLINE
DHCPRELEASE
DHCPINFORM
Please see RFC 2131 - Dynamic Host Configuration Protocolfor additional information.
If you are running Windows DHCP server and you have access to the box, you can use Windows PowerShell Scripting to query the DHCP database.
Excerpt from Weekend Scripter: Parsing the DHCP Database? No Way!
Summary: Microsoft Scripting Guy, Ed Wilson, talks about a Windows PowerShell function from the DHCPServer module that permits parsing the DHCP database.
I found this app that solve the problem
http://www.centrel-solutions.com/support/tools.aspx?feature=dhcpapi
I have some Pocket PC 4.2 Devices that communicate with a server wirelessly using WiFi via WCF. All works well until the wireless network is unable to connect to an AP and obtain a DHCP address (IP on the adapter is 0.0.0.0). At this point any WCF calls to the server will never return. If I assign a static IP to the wireless interface, this issue does not occur.
Below is the relevant code, generated by NetCFSvcUtil.exe. The call to Request() will never return. If the network adapter has a valid IP and the server is down, the connection will timeout with an exception as expected. I have tried adding a timeout parameter to the Request() call to no avail.
I can set the devices with static IPs or detect if the IP is invalid before attempting the WCF call, but I would like a better solution if possible, thanks!
private System.ServiceModel.Channels.Message getReply(System.ServiceModel.Channels.Message msg)
{
if ((this.RequestChannelFactory == null))
{
// transport doesn't support requests
throw new System.NotSupportedException();
}
System.ServiceModel.Channels.IRequestChannel requestChannel;
System.Threading.Monitor.Enter(this.RequestChannelFactory);
try
{
requestChannel = this.RequestChannelFactory.CreateChannel(this.remoteAddress);
}
finally
{
System.Threading.Monitor.Exit(this.RequestChannelFactory);
}
requestChannel.Open();
try
{
return requestChannel.Request(msg);
}
finally
{
if ((requestChannel.State == System.ServiceModel.CommunicationState.Opened))
{
requestChannel.Close();
}
}
}
I need to get an IP address for a given hostname from a DnsEndPoint, and convert it to an IPEndPoint. How would I go about doing this? WP7 lacks a Dns.GetHostEntry function, so is there any way to do this without creating a Socket, sending data to the host, then receiving a ping from the host and reading the RemoteEndPoint property to get the IP address of the host?
Try using DeviceNetworkInformation.ResolveHostNameAsync in the Microsoft.Phone.Net.NetworkInformation namespace, like this:
public void DnsLookup(string hostname)
{
var endpoint = new DnsEndPoint(hostname, 0);
DeviceNetworkInformation.ResolveHostNameAsync(endpoint, OnNameResolved, null);
}
private void OnNameResolved(NameResolutionResult result)
{
IPEndPoint[] endpoints = result.IPEndPoints;
// Do something with your endpoints
}
There is no way to do this built into the framework. You could use a socket assumming that the host supports ping. It will depend on the network you are running in (I'd assume you can't control this) and the exact requirements of the application.
It may be easier to get your app to work with IP addresses and not require a hostname if all you have is an IP address.
I think Im dealing with the same problem. I also have a dynamic IP updating the dns with No-ip.
For what I know the System.Net.Dns is not available in this version of Windows Phone.
Maybe in next releases.
http://msdn.microsoft.com/en-us/library/system.net.dns.aspx
At the start of my app Im going to create a web service call to the host (to the webserver in it) asking for the IPAddress. I think I'll solve the problem in the meantime.
This could be the WCF service
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetIpAddress(string value);
}
public class Service1 : IService1
{
public string GetIpAddress()
{
// Add the proper error handling and collection matching of course
IPAddress s = Dns.GetHostAddresses("www.mysite.com")[0];
return s.ToString();
}
}
If you guys find a direct approach please let me know