server talk headache

Blitz3D Forums/Blitz3D Programming/server talk headache

malicnite(Posted 2005) [#1]
Im having a problem with my server remote and server talking to each other i think it has something with the var streaming. here the code. dig thought it. and what is the code command one here its <code> </code> right

********************************************
.angmonserver
;insight
;the server is on the same computer as the server remote
;the to link but they dont stream right.
;the memory access error pops up for both.


;server remote
ExecFile("C:\Angmon.exe") ;the real server
Return

.talktoserver
angmonserver = OpenTCPStream("127.0.0.1",9090)
If angmonserver <> 0 Then
Print "Connected To Angmon"
Else
Print "Could Not Find Angmon's Server"
EndIf
While Not KeyHit(1)
scmd$ = Input("Sever Command: ")
WriteString angmonserver, scmd$
angmonstream = AcceptTCPStream(angmonserver)
If angmonstream Then
msgback$ = ReadString$(angmonstream)
Print msgback$
Else
EndIf
CloseTCPServer angmonserver
Wend

Return
*****************************************

*****************************************
angmonserver = CreateTCPServer(9090)

;the real server code
AppTitle "Angmon Server v1.00"

If angmonserver <> 0 Then
Print "Angmon Server Up"
Else
Print "Error Starting Angmon Server"
EndIf

While Not KeyDown(1)
angmonstream = AcceptTCPStream(angmonserver)
If angmonstream Then
cmd$ = ReadString$(angmonstream)
Print "Angmon Server Online"
Delay 1000
Else
Print "Angmon Server Online"
Delay 1000
EndIf
Gosub ref
Wend

.ref

If cmd$ = "status" Then
WriteString angmonserver, "Online"
Else
Return
EndIf
Return
*******************************************

please help


jfk EO-11110(Posted 2005) [#2]
Not sure if this will fix your problem, but it seems to me your usage of Gosub is wrong. The app starts at line 1 then executes line by line, then reaches the first Return without to know a return adress because it didn't GOSUB yet.

You may fix this like this:

Replace
Gosub label
by
label()

and

.label
by
function label()

and

Return
by
Return
End Function


Now you need to know, all variables that are used inside a function are locals, this means the function will forget their values as soon as the program returns from a function call. If you declare the variables to be global, they will not be locals and the functions will "remember" their value, as you meant to use them. eg.

Global angmonserver

Oh and BTW, it's a bad idea to use the same name for valiables and labels or function names.

The FOrum tags for code is [ code ] [ /code ], without the spaces. or use [ codebox ] for longer sources.


octothorpe(Posted 2005) [#3]
You need more experience coding simple programs before you start worrying about doing client/server stuff. Your program flow is scary, quite frankly.

Here's (some of) what's wrong:

1. your server accepts a new client every second, ditching any already connected clients.

2. your client is incorrectly using server commands such as AcceptTCPStream() and CloseTCPServer().

Look at the example code for AcceptTCPStream() to see how to correctly set up a client and a server. Better yet, forget about touching network stuff (which is harder to debug and understand) until you're much more comfortable with programming - specifically program flow.

Also, why aren't you posting in the Beginner forum?


malicnite(Posted 2005) [#4]
cause im not an begginer. as you can see im not making tetis like a noob. im making a freaken server. but thanks for the help


octothorpe(Posted 2005) [#5]
Please don't disparage other users who might be making Tetris clones. With the lack of program flow understanding you demonstrated above, I'd be suprised if you could write a Tetris clone without a lot of help; it's not as easy as you might think.


jfk EO-11110(Posted 2005) [#6]
I couldn't write tetris. Well I'd rather convert existing sources. But that's strictly copyright protected anyway.
A simple server/client app is a lot easier than tetris IMHO.

So, malicnite, don't feel offended. We all made these mistakes - but Octothrope of course, he was born with a "OO technics in 20 minutes" tutorial in his hands :P

I have to agree here, why don't you simply take the TCP Server sample from the docs, that's working well.


malicnite(Posted 2005) [#7]
i have the have that doc but the thing is that i need to put this project together and fast. see the system is for my game company. we are not a normal game company. we are online based. i need a system that can upload and down load concept art and storylines. i also need a system to talk to each other with. this sounds dumb, but i need it. i need a better programmer to do it if you say its to hard. if anyone is interested in this project i can pay you up to about 50 bucks. i no its not a lot but you can stay with the company and make alittle more. but we dont have much to offer now. if you want to try email me malicnite@...
also if im going to learn i dont like the little project that mean nothing. i want something that will mean something to the world. dont comment on this statement just watch for me. shylor kane


octothorpe(Posted 2005) [#8]
i need a system that can upload and down load concept art and storylines. i also need a system to talk to each other with.


Try CVS and an IM. Trying to write a custom solution when you can customize existing tools is masochism.

if im going to learn i dont like the little project that mean nothing. i want something that will mean something to the world.


You cannot learn like this. People do not learn like this. The most influencial mathematicians in history started out by counting beans. You cannot jump directly from zero to awesome - be prepared to put some work into it. Do the little projects that mean nothing until you learn everything you need to know for your bigger projects.

Software development is a lot like erecting a building. The code that you write becomes the floors of the building; as you progress, you build on the floors you've already built. If your architecture is well thought out, the floors will fit together nicely (easy to code) and the building will be sturdy (bug-free). If you have to change your plans part-way through, your foundation will be supporting renovations that were not planned for in your architecture; your building will not be as sturdy and will not fit together as well. Even if you go back and fix your load-bearing code, your design will likely never be as clean and sturdy as one that originally planned for things properly in the first place. It's entirely possible to reach a point where you cannot sanely keep building without going back and destroying entire floors, if not the entire building. The larger the project, the more important planning is, because you might never reach the top - and not through lack of trying. A skyscraper could not be built without a flawless plan: one mistake with the load-bearing members on the ground floor and the thing would never reach completion without crashing to the ground.

The moral of this mixed analogy is that huge projects require meticulous planning, meticulous planning requires understanding of the processes which will be employed, and this understanding would be reached far more easily with simple projects where there's less to worry about and less to be fixed when you make mistakes. You will make mistakes - everyone does. Mistakes are valuable for learning. Plan on making them. If you make 2 simultaneous mistakes on a small project, you may learn 2 valuable lessons. If you make 200 simultaneous mistakes on a large project, will you learn anything or simply have a huge mess on your hands that you don't understand?

If you don't want to learn, don't bother posting here - no one is going to do your project for you unless you offer money. If you're offering money, you might have better luck with a service oriented for that (e.g. rentacoder.com).

dont comment on this statement just watch for me


Huh? What are you like a superhero or something?


P.S. Do you want me to lend you my Shift key? I have two.