Sub Process_Globals
Public Serial1 As Serial
Private eth As Ethernet
Private ethServer As EthernetServerSocket
Private MacAddress() As Byte = Array As Byte(0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED)
Private const serverPort As UInt = 51042
Private astream As AsyncStreams
Private bc As ByteConverter
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
If eth.InitializeDHCP(MacAddress) = False Then
Log("Error connecting to network.")
Return
Else
Log("Connected to network. My ip address: ", eth.LocalIp)
End If
ethServer.Initialize(serverPort, "ethServer_NewConnection")
ethServer.Listen
End Sub
Sub ethServer_NewConnection (NewSocket As EthernetSocket)
Log("New connection")
astream.Initialize(NewSocket.Stream, "astream_NewData", "astream_Error")
End Sub
Sub astream_NewData (Buffer() As Byte)
Log("Received: ", bc.HexFromBytes(Buffer))
End Sub
Sub astream_Error
Log("Error")
ethServer.Listen 'need to call Listen after the connection broke.
End Sub