Can't send more than one string?

BlitzPlus Forums/BlitzPlus Beginners Area/Can't send more than one string?

Bergmann(Posted 2013) [#1]
I've been working on a basic chat client, and I've hit a brick wall. When I send a message to the server, it will send it, but then it refuses to send.
Client code:


Server Code:


Any help?


Yasha(Posted 2013) [#2]
...

This is going to sound off-topic, but trust me when I say that it isn't:

Please, please do not use Goto.

There are perfectly good loop structures and function definitions built into the language. You do not need to reinvent loops and procedures using Goto, nor should you. Whatever is wrong with your code is almost certainly hidden under the tangled mess of unreadable, untraceable structure you've created there. It's nearly impossible to follow already: it will drive the minds of men into the realms of darkness if you manage to spin this out into a full-size application. For the love of all that is holy, burn all of this now, don't look back, and start again.

If (I obviously have no way to gauge your skill level) you are using Goto because you are not yet familiar with real loops and procedures... then the most important thing to do right now is learn to walk before you run. Forget about complicated business like clients and servers until you can write the base code to host them!

I can't emphasise this enough. Do not use Goto. It is not proper code; it is highly deprecated; it is impossible to maintain; it is buggy by nature; and to add insult to injury it is usually slower than the alternative (not to mention that as you have discovered here, it plain doesn't work: among other things because you aren't using real loops, you aren't able to use the normal TCP idioms which is probably why your code doesn't work). If you wrote code like that at my company I would fire you on the spot; and if you write code like that here people will not help you because we cannot tell what is going on (let alone what is going wrong).


Look I know this sounds harsh and unfriendly, but it's a message that needs to get across as soon as possible: using Goto (especially like that) is simply not acceptable in the 21st century. Not if you want a) code that works, or b) other people to look at it. You will do yourself a huge favour if you learn the language-proper and the real constructs for the way you want to organise your code. The only reason Goto even exists in BlitzPlus is for compatibility with 80s BASIC projects; there is no reason to put it in new code. Newer languages have excised it altogether. (Being mean on the subject of Goto is my attempt at being friendly and helpful.)

There's a longer discussion/rant on the subject explaining it in more detail here: http://www.blitzbasic.com/Community/posts.php?topic=100046


If you really want an on-topic reply, my best guess (not at PC, can't run code to check) is that you're Accept-ing the TCP stream too often (in your receive loop?) and that you're checking for the end of data by trying to ReadString and get back "", when the correct way is to instead call Eof (which actually does check for the end of data and returns true in that case). But as I said, code with Goto is so hard to follow that you're unlikely to get helpful responses until you rewrite it to use loops and procedures.


Bergmann(Posted 2013) [#3]
Thank you. I find that for most of these, a repeat loop would work.


Wings(Posted 2013) [#4]
Better late then never.. not faulty goto coding it rocks good.


;Replace in the server code and your chatt will work.
If Not stream Then stream=AcceptTCPStream(server)