GNet Message woes

BlitzMax Forums/BlitzMax Beginners Area/GNet Message woes

Queller(Posted 2007) [#1]
So, I am new to BlitzMax and I am trying to figure out how to use GNet messages to simply send text input from one IDE instance to another on the same machine.

To get a feel for this I stripped down Mark's gnet space shooter demo and came up with these: a receiver and transmitter using normal GNet slots first...

========
Receiver
========

Strict

Const GAMEPORT=12345

Const SLOT_TYPE=0

Local host:TGNetHost=CreateGNetHost()
Local obj:TGNetObject=CreateGNetObject(host)
Local remoteObj:TGNetObject

Local success = GNetListen( host, GAMEPORT )
If Not success Then RuntimeError "GNetListen failed" Else Print "Listening"

While Not KeyHit( KEY_ESCAPE )
GNetSync host

For remoteObj = EachIn GNetObjects( host, GNET_MODIFIED )
Local msg:String = GetGNetString(remoteobj,SLOT_TYPE)
If msg <>"" Print msg
Next

Wend

===========
Transmitter
===========

Strict

Const GAMEPORT=12345

Const SLOT_TYPE=0

Local host:TGNetHost=CreateGNetHost()
Local obj:TGNetObject=CreateGNetObject( host )
Local message:TGNetObject=CreateGNetMessage(Host)

Local success = GNetConnect(host,"localhost",GAMEPORT, 10000)
If Not success Then RuntimeError "Connect failed" Else Print "Connected"

While Not KeyHit( KEY_ESCAPE )
GNetSync host
Local c:String=Input("Type something!!! > ")
SetGNetString(obj,SLOT_TYPE,c)
Wend

Now, if I try the same thing but adapt both of these to use Gnet messages, it doesn't work even though I am doing what I am supposed to do, as far as I can tell. Below is the code for using messages instead...

========
Receiver
========

Strict

Const GAMEPORT=12345

Const SLOT_TYPE=0

Local host:TGNetHost=CreateGNetHost()
Local obj:TGNetObject=CreateGNetObject(host)
Local remoteObj:TGNetObject

Local success = GNetListen( host, GAMEPORT )
If Not success Then RuntimeError "GNetListen failed" Else Print "Listening"

While Not KeyHit( KEY_ESCAPE )
GNetSync host

For Local msg:TGNetObject = EachIn GNetMessages(host)
Local text:String = GetGNetString(msg,SLOT_TYPE)
If text <>"" Print text
Next

Wend

===========
Transmitter
===========

Strict

Const GAMEPORT=12345

Const SLOT_TYPE=0

Local host:TGNetHost=CreateGNetHost()
Local obj:TGNetObject=CreateGNetObject( host )

Local success = GNetConnect(host,"localhost",GAMEPORT, 10000)
If Not success Then RuntimeError "Connect failed" Else Print "Connected"

While Not KeyHit( KEY_ESCAPE )
GNetSync host

Local c:String=Input("Type something!!! > ")
Local message:TGNetObject=CreateGNetMessage(Host)
SetGNetString(message,SLOT_TYPE,c)
SendGNetMessage(message, obj)
Wend


Can anyone help me fix what's wrong with this? Thanks!


Queller(Posted 2007) [#2]
This seems to be a problem many people have. Has no-one worked on something like this with success?


GfK(Posted 2007) [#3]
Haven't done any of this myself, but somebody mentioned a while ago, that when you're using localhost to test two copies of your program on the same PC, you need to be using different port numbers.


Derron(Posted 2007) [#4]
Sure you need two ports... otherwise the networkbase wouldnt know which packet has to be routed to which application.

If you have a strictly acting firewall, be sure to enable both ports (not needed in original windowsfirewall of XP).

If you try it on local lan (different PCs) and you are not using a router (so really local and no usage of WAN-IP) you can use the same port - coz of different IPs. Otherwise, using WAN (Internet-IP) you need to set up different ports and on your gateway you have to route the ports to the desired local-IPs.


bye
MB