Welcome! Log In Create A New Profile

Advanced

How to use sockets?

Posted by John 
John
How to use sockets?
October 17, 2008 06:45PM
Hi All,

I know the basic premise behind using sockets. I'm wondering if anyone has any example of how to use sockets to connect to an external source

I'm specifically wanting to connect to Whois, supply a domin name and validate it.

Thank you
John
BLS
Re: How to use sockets?
October 18, 2008 03:07AM
Hi John :

//Port Number : 43

sDomain is string = "pcsoft.fr"
sNIC is string = "whois.nic.fr"

IF SocketConnect ("WHOIS", 43, sNIC)  THEN

        //CRLF = \r\n

	SocketChangeTransmissionMode("WHOIS",SocketEndTagBuffer,CRLF)
 	
	SocketWrite("WHOIS", sDomain)

	s is string  = SocketRead("WHOIS")
	Trace(s)	
	WHILE s <> ""
		s = SocketRead("WHOIS")
		Trace(s)
	END
	SocketClose("WHOIS")
	
END

As always : code pretty much untested. [Edit : modified and slightly tested]
HTH, Bjoern




Edited 5 time(s). Last edit at 10/18/2008 04:05AM by BLS.
John
Re: How to use sockets?
October 18, 2008 05:38PM
Hi Bjoern

Thanks so much for the code... This is a great starting place.

John
BLS
Re: How to use sockets?
October 18, 2008 07:04PM
Hi John,
first of all : hope you read my previous message on mysnip. The code showed on the pcs newsgroup is buggy...
However, you may find this function usefull as well.

PROCEDURE WhoIs_Domain( LOCAL domain is string = "" )
	response is string = ""
	extension is string
	pos is int
	size is int
	
	domain = NoSpace(domain)
	
	IF domain = "" THEN RESULT ""
	
	// extract domain extension
	size = Length(domain)
	pos = Position(domain, ".", size, FromEnd)
	
	IF pos = 0 THEN RESULT ""
	
	extension = domain[[pos +1 TO size]] 

	// connect to extension + .whois-servers.net
	IF SocketConnect( "WHOIS_DOMAIN", WHOIS_PORT, extension + ".whois-servers.net" ) THEN

		// change transmission mode
		IF SocketChangeTransmissionMode( "WHOIS_DOMAIN", SocketEndTagBuffer, CRLF ) THEN
		
			// send request
			IF SocketWrite( "WHOIS_DOMAIN", domain  )

				// get response
				response = SocketRead( "WHOIS_DOMAIN" , False )
			END
		
		END
		
		SocketClose("WHOIS_DOMAIN")
	END
	
RESULT response


You can use this code to find out which whois server belongs to a specific top level domain.

Try : Trace(WhoIs_Domain("kernel.org"))

Enjoy Bjoern
PS : Guess you are a PHP wizard so I hope you can help smiling smiley

//PHP
	// $matches=array();
	// preg_match('@^ReferralServer: whois://(.*)$@Um',$response,$matches);
I've some problems to translate this php code into Windev..
I think the ^ means : Only at the beginning ???
The $ means from the end ???
Any ideas how to translate this PHP reg.expression into Windev by using MatchRegularExpression() / Middle() and such ?
TIA Bjoern




John
Re: How to use sockets?
October 20, 2008 05:59AM
Thanks, this works nicely!

With a little modificaiton (checking the return value) I'm able to determine if the domain is available or in use.

THANKS AGAIN !
John
Mehwesh
How to download video?
November 10, 2008 07:45AM
i need help in downloading videos by WinDev user agent with url encode.
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: