Connecting 2 Monkey apps via TcpStream ?

Monkey Forums/Monkey Programming/Connecting 2 Monkey apps via TcpStream ?

tOmzone(Posted 2013) [#1]
Hello people,

maybe its a dumb question but: is it possible to connect 2 monkey programs via the TcpStream classes from BRL module? I looked through the forums to find some examples etc. but i only found some code for HTTP requests/getting the source of a website.

I'd like to establish a client-server architecture. Using tcp sockets in other languages (Blitzmax for example) you have a method like "GetNewConnectingClient" or sth like that which returns any incoming connection.
Is that also possible with monkey? Maybe I missed something.

Greetings


Rushino(Posted 2013) [#2]
I know TcpStream can do this. However there isn't much example around. I was looking for an example too but i couldn't figure out how it would work. But to answer your question i believe yes its possible. You could also do like i did instead of using regular sockets.. use websockets.. i made a lib in the module section called MkWebSockets. This way you could use WebSockets technologies to make your architecture. This seem to be good only if you intent to put your game on a web browser through as one of your target you support. If you don't need this then regular sockets can do but you will have to figure out how streams work with monkey.

http://www.monkeycoder.co.nz/Community/posts.php?topic=3884

There is also other poeple that made sockets libs if you look in the user module section. That might be interesting to you.


Xaron(Posted 2013) [#3]
As far as I see this is not possible with the current implementation. You need something to create a host which listens on a specific port.


Midimaster(Posted 2013) [#4]
work around:

In my Cheese Box game ( http://www.monkeycoder.co.nz/Community/topics.php?forum=1220&app_id=220 )I use a HTTP server as a relay station for communication between two monkey apps. The php script only received the messages as a HTTP-Post...

http://www.mypage.com/Game.php?ID=1&X=13&Y=8


...and stores them until the receiver asked for them. Then it sends it as a html page:

<html>
X=13
Y=8
</html>



Rushino(Posted 2013) [#5]
Nice work around. If you go the web sockets route.. you also need a server to listen on a specific port. I have done it in C# through using a lib.


Xaron(Posted 2013) [#6]
Midimaster, that's the way I'd use myself as well. But why do you send the "<html>" tags? Wouldn't it be enough to just do an echo command in PHP?


Hummelpups(Posted 2013) [#7]
jep, that html tag is useless


Midimaster(Posted 2013) [#8]
yes it is useless. i did not do it! I only want to demonstrate in the post, that the answer is like a received html page done with simple "echo" commands on php.

You can of course return a simple plain text or a XML based lines or whatever you want.

At the end the bottle neck of this system is not the returned file, because it can be as big as you want. The problem is more to pack all datas into an URL string and keep it valid...


Sub_Zero(Posted 2013) [#9]
tOmzone: what target will you be building to?

For android, you could use the anet module, or mnet for another target.
I haven't tested the build in one, but that should also work.

Blitzmax will be good as server