View Full Version : alright, TCP routines finished. download them here.

Mike Chambers
September 25th, 2006, 11:11 PM
sorry i know i've been starting alot of threads in this subforum heh.
but my TCP routines for the trumpet TCP stack are finished. it's for quickbasic, as i'm sure you've noticed by now... you can write server apps too. i figure it's always good to have new tools to program DOS net apps if you use vintage x86 machines alot.

it doesn't detect the tcpdrv interrupt right now, you have to initialize it with a function:
tcpInit(&H61) <---- 61h is the usual interrupt. the function returns an integer result, 1 = success, 0 = fail... although it locks the sysem up if it fails anyway. i will probably work on making it detect automatically, sorry.

use the tcpListen%(port) function to open a listening port. it returns the socket's handle as an integer.

to wait for the listening port to get a connection, just keep checking tcpStatus%(handle) for the sckOpen constant.

for opening an outward socket, the function is:
tcpConnect%(RemoteIP string, RemotePort integer)
it returns a handle too of course.

to send a packet, use this subroutine: (limit the data string to 1500 bytes)
tcpSendData tcpHandle as integer, Data2Send as string

to get any waiting packet data, call this function: (reads from the input queue 1500 bytes at a time)
tcpGetData$(tcpHandle as integer)
it returns a string, of course

tcpStatus%(tcpHandle) function returns a handle's connection status. it'll be one of these constants:
sckClosed (a 0 can also mean it's closed)

tcpDoIO is just a subroutine you should call periodically to get TCPDRV to process packets.

it's good to use the tcpClose (tcpHandle as integer)
subroutine after you're done with a handle, because it frees them for reuse.

you can read important info about the network settings with some of these:
tcpDriver.LocalIP (long integer)
tcpDriver.LocalNetmask (long integer)
tcpDriver.LocalGateway (long integer)
tcpDriver.LocalDNS (long integer) - your dns host's IP
tcpDriver.LocalDomain (256 byte string)
tcpDriver.DomainLen (integer) - use this to trim the LocalDomain string.
tcpDriver.Timeserver (long integer)
tcpDriver.ErrorCode (integer) - i made these constants you can use: errBadCall, errCritical, errNoHandles, errTimeout, errBadsession. this gives any error code that the last function you ran may have returned.

to convert any of the long integers to an IPv4 string, use the Conv2IP$(long integer) function.

i've included the source for some example programs i've written to show how to use the routines. i included a telnet client, telnet server, and an HTTP downloader. the routines seem extremely stable and don't lose any packets at all. i downloaded a 240 MB AVI file to my 386 with my HTTP downloader example from the linux box on my LAN, and it came out flawlessly and played fine.

the only thing i might add later and make a version 2.0 for, is hostname dns resolution. i haven't done that yet.

i've never really messed with DNS on such a low level.... i'll need to read up on it. if anybody has some good info, and maybe some example queries/response packets let me know please!

i'm attaching NTCPQB10.ZIP to this post. i hope somebody can make good use of this, i know i will. :p

Mike Chambers
September 25th, 2006, 11:18 PM
deleted. sorry.

Mike Chambers
October 4th, 2006, 01:20 PM
i made a mistake when i first uploaded that attached ZIP file... i forgot to put instructions on the readme.txt file, and i forgot to put NTCPDRV.EXE file in it too.

anyway, i fixed the ZIP to how it should be and re-attached it just now. sorry! :stupid:

i doubt many people here will use this, because most probably know more advanced and/or faster programming languages than quickbasic. i thought i'd share it anyway. BASIC is easily powerful and fast enough to make small internet apps with.

btw, sometime in the next day or so i will be ready to share version 1.1 - HUGE feature i'm adding... DNS resolution :twisted:

October 4th, 2006, 01:40 PM
Cool, looks like you're very well underway in your project Mike, I'm really interested in what's going to happen to this :-).

THank for keeping us posted. DNS resolution huh? groovy.