Author | Topic: Whois - my first ASINet Programm | |
---|---|---|
Stephan Koenig | Whois - my first ASINet Programm on Wed, 06 Mar 2002 21:42:18 -0500 Hi, I just downloaded ASINet about about an hour ago or so. (Working on the upgrade on internal lines for ages). Using the sample i was able to get a small programm running. I have to query a whois-server on Port 43. The only problem I have is, that I do not know in advance how many bytes I will be recienving. How do I have to modify my code to handle that ? THANKS FOR ANY HINT Stephan PROCEDURE Main LOCAL nPort := 43 LOCAL CServername := "whois.networksolutions.com" LOCAL nSocket LOCAL cBuffer LOCAL nBytes LOCAL nError := NIL LOCAL CDomain := "test.com" nSocket := SocketOpen( SOCK_STREAM, cServername, nPort, @nError ) IF nError <> 0 ? "ERROR:" + LTrim(Str(nError)) ENDIF SocketSend( nSocket, CDomain+chr(13)+chr(10) ) nBytes := 3000 <-------------- DAS MEINE ICH ! cBuffer := Space( nBytes ) nBytes := SocketRecv( nSocket, @cBuffer, nBytes, @nError ) SocketClose( nSocket ) IF nError <> 0 cBuffer := "ERROR:" + LTrim(Str(nError)) + " BYTES RECEIVED:" + LTrim(Str(nBytes)) ? cBuffer ELSE ? cBuffer ENDIF RETURN | |
Andreas Herdt | Re: Whois - my first ASINet Programm on Thu, 07 Mar 2002 11:42:58 +0100 Hi, What you are describing is the principal problem of a server: a client is connecting and now the server has to find out what the client is about to do. Thechnically spoken, there must be a protocol on above the tcp protocol, client and server have to do any kind of handchake and communication. As example you can think of any protocol which is sitting on tcp/ip. Think of HTTP, FTP, SMTP, POP and so on. To your problem: 1) You can create an own protocol, for example let the first n Bytes be the length of the message. This works since the client knows about the message length (usually). This way the server can read the first n bytes first and thereafter tries to read as long as everything is read. 2) Another strategy is that the client is writing a special EndOfStream sequence at the and of the message and the server reads as long as he finds this code sequence. 3) Another one is that the message is of a defined length. Solutions: 1) read the first n bytes and allocate a suitable buffer. 2) allocate a buffer of any size and read until endofstringmarker and concatinate the different parts of the message. 3) a suitable buffer may be allocated in advance. Hope this helps. -- Andreas Herdt Alaska Software Technology AG ------------------------------------------------------------- Technical Support EMEA: mailto:support@de.alaska-software.com Technical Support APRA: mailto:support@us.alaska-software.com News Server: news://news.alaska-software.com Homepage: http://www.alaska-software.com ------------------------------------------------------------- "Stephan Koenig" <S.Koenig@LaserPlus.de> schrieb im Newsbeitrag news:3c86d2b0$1@asgcom.alaska-software.com... > Hi, > > I just downloaded ASINet about about an hour ago or so. (Working on the > upgrade on internal lines for ages). > > Using the sample i was able to get a small programm running. I have to query > a whois-server on Port 43. > > The only problem I have is, that I do not know in advance how many bytes I > will be recienving. How do I have to modify my code to handle that ? > > THANKS FOR ANY HINT > > Stephan > > > PROCEDURE Main > LOCAL nPort := 43 > LOCAL CServername := "whois.networksolutions.com" > LOCAL nSocket > LOCAL cBuffer > LOCAL nBytes > LOCAL nError := NIL > LOCAL CDomain := "test.com" > > nSocket := SocketOpen( SOCK_STREAM, cServername, nPort, @nError ) > > IF nError <> 0 > ? "ERROR:" + LTrim(Str(nError)) > ENDIF > > > SocketSend( nSocket, CDomain+chr(13)+chr(10) ) > > > nBytes := 3000 <-------------- DAS MEINE ICH ! > cBuffer := Space( nBytes ) > nBytes := SocketRecv( nSocket, @cBuffer, nBytes, @nError ) > > SocketClose( nSocket ) > > IF nError <> 0 > cBuffer := "ERROR:" + LTrim(Str(nError)) + " BYTES RECEIVED:" + > LTrim(Str(nBytes)) > ? cBuffer > ELSE > ? cBuffer > ENDIF > > RETURN > > | |
Stephan Koenig | Re: Whois - my first ASINet Programm on Thu, 07 Mar 2002 06:44:37 -0500 Thanks Andreas. Well, WHOIS is a defined standard and I asume that I will not get Networksolutions (oder Denic) to change their protokol fr me Does a to large buffer slow down the transmission or even cause to wait for a timeout ? Thanks Stephan | |
Andreas Herdt | Re: Whois - my first ASINet Programm on Fri, 08 Mar 2002 10:42:47 +0100 "Stephan Koenig" <S.Koenig@LaserPlus.de> schrieb im Newsbeitrag news:3c875206@asgcom.alaska-software.com... > Thanks Andreas. > > Well, WHOIS is a defined standard and I asume that I will not get > Networksolutions (oder Denic) to change their protokol fr me > > > Does a to large buffer slow down the transmission or even cause to wait for > a timeout ? > > Thanks > > Stephan My fault, I have not recognized that you are working with clients which you can't control. As far as I can see, following will solve the problem: Try to read as long as there is incoming data. cRecv := "" cBuffer := Space( 4096 ) do while 0 != ( nBytes := SocketRecv( .....cBuffer..... ) ) cRecv += Substr( cBuffer, 1, nBytes ) enddo Don't worry on speed here. 4 kB is quite a good cache size. Xbase++ does not have any performance problems on allocating such a small amount of memory, and the socket layer will not loose speed working with larger buffers then incoming data. On operating system level the whole string is just allocated memory with a pointer on it. The data is copied and the pointer is moved as long there is incoming data. when there is no more data, this stops. Hope this helps. -- Andreas Herdt Alaska Software Technology AG ------------------------------------------------------------- Technical Support EMEA: mailto:support@de.alaska-software.com Technical Support APRA: mailto:support@us.alaska-software.com News Server: news://news.alaska-software.com Homepage: http://www.alaska-software.com ------------------------------------------------------------- | |
Stephan Koenig | Re: Whois - my first ASINet Programm on Mon, 11 Mar 2002 21:56:00 -0500 Great, thanks. Thats what I wanted to hear. |