View Full Version : Connecting to an Established Server

07-07-2009, 06:34
Hi Folks,

I need a little help.

I wish to connect to a database server. The database is powerful but character based.

Once I successfully establish a connection (TCP/IP is normally used), I understand I will be able to communicate effectively using the udp_send and udp_receive functions to send and receive text strings.

I'm having trouble establishing the initial connection. My attempts have been based on my (demonstrably inadequate) understanding of the UDP_Notify_Client.tbasic program.

I need to establish a TCP connection (with "localhost" initially, for testing purposes), on server port 2300.

Once connection is established, I will send a carriage return to elicit a "Login:" request. Replying to that will trigger a "Password:" request, to which I will reply in turn. After that, I should be able to happily pass text strings backwards and forwards between my thinBasic program and a control program on the server.

Can anyone give me a few clues re establishing the initial connection, please?


Peter H.

John Spikowski
07-07-2009, 10:39
Hi Peter,

Until you get a thinBASIC solution worked out, this should do it for you.

C:> sendit mycmds.txt

If it works, try redirecting commands from the console or redirecting output to a file.

FileName = COMMAND()
LINE INPUT #1, FileCmd
PRINT #2, FileCmd
LINE INPUT #2,Response
PRINT Response

Note: Untested Program.
I attached a zip that has sendit.exe

Petr Schreiber
07-07-2009, 13:27
Hi Peter,

and welcome to ThinBASIC forums!

Could you please post code you use currently for connecting to database?


07-07-2009, 15:00
Hi everyone there,

i have to say that i'm a little bit confusion.
just, i was reading Peter here, but i was not meant here.
i think you could write for the other Peter : [Peter H] in order to differentiate both names !
i get psychic problems, if i do ascertain that i cannot do this and this.


08-07-2009, 09:39
Hi folks,

This is my 4th attempt to send the mentioned attachment.

It was in .doc form the first time, and rejected.

My second attempt, with a .zip file, was rejected because it was a duplicate post.

So was my third attempt, with totally different text.

I've totally exited and come back in this time. My fingers are crossed.



Michael Clease
08-07-2009, 09:55
Peter can you post the "serverconnectmvb.tbasicc" file or do you really expect people to type all that in to try and help?

can you send and receive on the same channel ?

08-07-2009, 15:56
Hi Folks,

It looks like my first post pertaining to the attachment, and all the text in it, was lost. Sorry.

An attachment error was reported the first time because the attachment was a .doc file. When I tried again with a .zip attachment, the post was rejected because it was a duplicate, so I thought the text had been accepted the first time. It hadn't been.

So I re-typed the the original text from memory, only to have it rejected because someone had replied to my one post that had got through. (That was Michael's reply, for which I am grateful.)

With all the posting problems, I was extremely late already (having to take my wife somewhere important), so I just had to shut down and run.

For the record, a summary of my latest rejected post is: (Reply to Michael after this)
Thank you everyone for your responses.

I rediscovered the TCP_ functions in the documentation. I had forgotten them because of information overload.

I started from scratch, using them.

I seem to be connecting to the server OK.

I don't receive the response I expect. The expected response, as received by a PC-based terminal emulator, is shown on page 2 of the attachment in the former post that got through. Such emulators require only the destination IP address and port number to be specified by the user.

I guess I must be mis-using either the TCP_Open or TCP_Recv command.

All advice will be welcome and appreciated.

Kind regards to all,

Michael, thanks for your reply.

I posted only a screen dump because I thought somebody would see what I was doing wrong just by inspection. I hadn't expected anyone to actually want to run my code and experiment with it.

I appreciate your gesture. My code is attached. (I've also tried using TCP_Print instead of TCP_Send.) For test purposes, I am using a database on my local computer, so if by channel you mean port, the answer is I don't think I can send and receive on the same channel. Port 2300 is reserved for the database.

Kind regards,

Peter H

08-07-2009, 16:26
Hi Michael,


When considering only the client end of my communication, port 2300 is immaterial. My mistake. After midnight here.

To answer your question more accurately, I do not know if the client (thinBasic) program can send and receive on the same channel (port). However, I suspect that it can, because the database (server end) both sends and receives on only one port, being 2300.

Kind regards,

Peter H.

Michael Clease
08-07-2009, 16:46
Thanks for posting the script its sometimes quicker to look at what someone has done

you have some mistakes

TCPOpenFile has the error flag from TCP_OPEN not a handle, you should be using TCPFreeFile

inBuffer = TCP_Recv(TCPFreeFile,6000)

but I get an error 57 at work havent tried at home but try my version below see what you get.


oops slight bug but thanks Petr...now fixed

08-07-2009, 19:24
hi peter h., michael, petr :)

perhaps somebody can check the current tcp script again...

I have started the debugger again and have got at line 28 of the script an error code 57 (again!)... :) the picture I am attaching...

I have downloaded the current script and here the little mistake stills exists ... sorry... or my pc has a cold... ;)

best regards, Lionheart

Petr Schreiber
08-07-2009, 19:38

I can confirm, 57 is "Device I/O" error I think.
Could it mean "blocked by firewall"?


Petr Schreiber
08-07-2009, 20:30
I don't know how to do server in ThinBASIC,
so I created one in PowerBASIC, and made it talk with ThinBASIC, so you can try here.

How to use:

Run TcpServerTest.exe ( Windows firewall might complain, click "Unblock" )
Run TcpClientTest.tbasic

Please run TcpServerTest.exe first, else you will get error 57!


Michael Hartlef
08-07-2009, 22:14
Hi Peter,

welcome to the forum.

Petr, is it really possible to have two thinBasic scripts running at the same time?

Petr Schreiber
08-07-2009, 22:22
Hi Mike,

I am not sure I understand the question :unguee:

You just execute the EXE, let it run, and then run the script, as seen on picture

Michael Hartlef
08-07-2009, 22:36
Yes I see. But you mentioned a server done in thinBasic. So a client and a server running at teh same time on one computer. Is that possible?

Michael Hartlef
08-07-2009, 22:38
Forget it, works.

Michael Clease
09-07-2009, 09:00
Thanks Petr I had brain block going on. Of course it needed a server. DOH!

Mike if you look at the UDP samples it required two scripts running a server and a client but I suspect thats what your previous post refered to.

Michael Hartlef
09-07-2009, 09:18
Thanks Petr I had brain block going on. Of course it needed a server. DOH!

Mike if you look at the UDP samples it required two scripts running a server and a client but I suspect thats what your previous post refered to.

Yes, I looked at them. :)

10-07-2009, 09:51
Hi Folks,

Thank you for the welcomes to the forum.

Michael and Petr, your client programs worked like a charm. They opened a connection to the database and I was able to send and receive data. Thank you.

At first I was receiving error messages from the database, but at least the database was talking to me. I had to play with the database comms settings to get it to work properly, but at last I am receiving the initial response I was looking for.

I can now polish the login process up, and then progress to the next step - controlling the database from within thinBasic.

Thanks also to everyone else who responded.

thinBasic appears to be ideal for what I am trying to do. Top marks to all of you who contributed (and are contributing) to its development.

Because it is a new environment for me, I may yet need to ask the odd question or two (or three, or four, ....) in the future.

I hope that one day I may be able to return the favour by offering help to others.

Kind regards,

Peter H.