We help IT Professionals succeed at work.

Converting Port number name in integer

Medium Priority
276 Views
Last Modified: 2013-11-13
Hi There,

I am using VB 5 with Winsock. My VB program first retrieves the hostname and the port number from the local registry. My port number in my registry is defined as name and the number can be retrieved in the services file.

Question : how can I convert the port name in integer or how can I retrieve the socket number in my services file
from VB ??

Second question : how can I check if my remote port number is listening on my port defined in my registry ??
                                which message can I catch from VB if the remote port number is not listening to ??
Comment
Watch Question

Commented:
To get the port number, take a look at the getservbyname function. It's a little tricky since it returns a pointer.
I'm not too sure what you're asking but to convert a string to an integer is CInt(PortNumber).

For second question:
so you're running a clientSocket and you want to know if the remote ServerSocket is listening to it's port? I don't think you can, since you don't have a connection with the server yet, otherwise, you can probably get properties like RemotePort and stuff like that.

Hope it helps.

Commented:
yves_hardy, you should consider splitting this into two separate questions, the two questions aren't directly related and it might help you get an answer. I think the second question also needs to be clearer.

Commented:
on Question 1:
platiumstar is right all you need is the CInt("123") or CLng("123") if you want a long.

on Question 2:
On you second question, If it's a dialup you can check your RAS (DUN) to see if your connected then do a :
============================

on error resume next
Dim oObjectName as Object
   Set oObjectName = CreatObject("Object.class", "MachineName")

===========================

ohhh sh$#.. I'm sorry your are using VB5?  The above code is VB6, that would be something for you to look forward to int eh future.  

Since your using VB5 go to my site at http://www.karland.com/OurProducts/DCom32/ and download the DCOM32.OCX.

This DCOM32.OCX will alow you to put in two parms like above and it's FREE. If you need a non-interface DLL contact me and I will convert the OCX into a ActiveX DLL and send it to you.  
Then the code would be :

===========================
on error resume next
Dim oObjectName as Object
   Set oObjectName = DCOM321.ConnectToServer("Obeject.class","MachineName")

Then:
===========================

if err.number <> 0 then
   Msgbox "Error: " & err.number & chr(13) & err.description: exit sub
endif
===========================

If you need the DUN call for connection tell me I have written a KRAS32.DLL that will connect, disconnect, add DUN, edit DUN, custom icon, and much much more.
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Commented:
of course in my code above strService should be set to the service you want, for example strService = "nntp"
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.