what is wrong? i can connect but OnAcceptComplete is not called!? (i try glfw/Desktop Game)
Strict
Import mojo
Import brl.socket
Import brl.filestream
Class Server Implements IOnAcceptComplete
Method OnAcceptComplete:Void ( socket:Socket, source:Socket )
Print("OnAcceptComplete")
Local data:DataBuffer=Null
Local offset:Int=0
Local count:Int=0
socket.ReceiveAll(data, offset, count )
Local file:FileStream=FileStream.Open("input.txt","w")
file.WriteAll(data,0,data.Length())
file.Close()
End
End
Class MainApp Extends App 'Implements IOnAcceptComplete
'Class MainApp Extends App Implements IOnAcceptComplete did not work^^
Field socket:Socket
Field server:Server
Method OnAcceptComplete:Void ( socket:Socket, source:Socket )
Print("OnAcceptComplete")
Local data:DataBuffer=Null
Local offset:Int=0
Local count:Int=0
socket.ReceiveAll(data, offset, count )
Local file:FileStream=FileStream.Open("input.txt","w")
file.WriteAll(data,0,data.Length())
file.Close()
End
Method OnCreate:Int()
SetUpdateRate(60)
server = New Server()
socket = New Socket("server")
If socket.Bind("",80)=True Then 'should do same .Listen from VB6 Winsock OCX
Print("Bind to localhost Port 80 OK :)")
'socket.AcceptAsync( Self )
socket.AcceptAsync( server )
'Local s:Socket=socket.Accept()
'If s<>Null Then Print("Accept") 'geht
Else
'können ein paar Dienste verhindern^^
Print("Bind to localhost Port 80 failed...")
End
Return 1
End
Method OnUpdate:Int()
UpdateAsyncEvents()
If KeyHit(KEY_ESCAPE)=1
EndApp()
Endif
Return 1
End
Method OnRender:Int()
Cls 32, 64, 128
PushMatrix
Local sx:Float= Float(DeviceWidth()) / 800.0 '1920.0
Local sy:Float= Float(DeviceHeight()) / 600.0 '1080.0
'Local mx:Float= 1920.0 / 2.0
'Local my:Float= 1080.0 / 2.0
Local mx:Float= 800.0 / 2.0
Local my:Float= 600.0 / 2.0
Scale sx,sy 'resize to hd
Translate mx,my 'move to middle of the screen
SetColor(128,128,128)
DrawLine(-mx,0,mx,0)
DrawLine(0,-my,0,my)
SetColor(255,255,255)
PopMatrix
Return 1
End
End
Function Main:Int()
Local mainApp:MainApp =New MainApp
Return 1
End
|