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!
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!