0
Hello, I’m making a communication with an equipment using socket.
I’m using the library System.Net
to convert the ip and pass the port as parameter in the IPEndPoint
to use in the SocketEquipamento.Connect
I’m doing it this way:
IPAddress ipAddress = IPAddress.Parse("192.168.000.077");
IPEndPoint remoteEP = new IPEndPoint(ipAddress, port);
SocketEquipamento.Connect(remoteEP);
Console.WriteLine("Conectado com sucesso");
Thus 192.168.000.077
the IPAddress.Parse
is converting to the ipAddress
the following result 192.168.0.63
If you pass the ip 192.168.0.77
it keeps the ip and makes the connection.
I wonder why he’s doing this when he passes 192.168.000.077
.
Is there another way to make this conversion? Or should I have a treatment when receiving the ip taking the 0
lefty?
Has some function already
System.Net
who does this check? If there is no example of treatment in this case?– mba
I don’t understand your question... nay use zeros on the left:
IPAddress ipAddress = IPAddress.Parse("192.168.0.77");
– zentrunix
Yes I understood I must use
192.168.0.77
, however I need to remove these zero why the ip and dynamic I spent fixed on the question just to be more clear what is happening.– mba
if you are reading these numbers from a configuration file, then generally you too nay should use numbers with zeros on the left in the configuration file
– zentrunix
This coming from a database, I need a function that takes these zeros, do you know any? I thought to use the
Replace
but will remove all zeroes.– mba
I don’t work with C#, but I imagine you can test if the field is all filled with zeros, in this case you replace with only one zero...in the other case I imagine that Replace should be enough...otherwise I can’t help but have no experience with C#
– zentrunix
Thanks, I managed to solve creating a method that does this.
– mba