Prop+ethernet example...
KamPutty
Posts: 48
Hi all,
Well, I'm trying to get a simple "hello world" working showing how to create a tcp/ip server. I've taken code from around, and have created my first test showing a server waiting on port 80 (web)...and just waits for a connect...then I can expand that.
Unfortunately, it does not wait, it always "connects"... ...me thinks (me knows! ) I've done something wrong!
Here is the sample code
Looking at the code for the
it does not look like it blocks, hence the repeat...
All I have set my IP's...etc...
Thoughts?
~Kam (^8*
Well, I'm trying to get a simple "hello world" working showing how to create a tcp/ip server. I've taken code from around, and have created my first test showing a server waiting on port 80 (web)...and just waits for a connect...then I can expand that.
Unfortunately, it does not wait, it always "connects"... ...me thinks (me knows! ) I've done something wrong!
Here is the sample code
' simple ethernet test CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 OBJ term : "TV_Text" settings : "settings" nic : "driver_socket" DAT MAC BYTE $de, $ad, $be, $ef, $ca, $fe IP BYTE 10, 200, 1, 142 MASK BYTE 255, 255, 255, 0 GATEWAY BYTE 10, 200, 1, 1 DNS BYTE 10, 0, 0, 1 VAR long stack[noparse][[/noparse]100] PUB init | i settings.start settings.setData(settings#NET_MAC_ADDR,@MAC,6) settings.setData(settings#NET_IPv4_ADDR,@IP,4) settings.setData(settings#NET_IPv4_MASK,@MASK,4) settings.setData(settings#NET_IPv4_GATE,@GATEWAY,4) settings.setData(settings#NET_IPv4_DNS,@DNS,4) ' Start the TV Terminal term.startWithMode(12,term#MODE_NTSC) if settings.getData(settings#NET_MAC_ADDR,@stack,6) term.str(string("MAC : ")) repeat i from 0 to 5 if i term.out("-") term.hex(byte[noparse][[/noparse]@stack][i],2) term.out(13) if settings.getData(settings#NET_IPv4_ADDR,@stack,4) term.str(string("IP : ")) repeat i from 0 to 3 if i term.out("-") term.hex(byte[noparse][[/noparse]@stack][i],2) term.out(13) if settings.getData(settings#NET_IPv4_MASK,@stack,4) term.str(string("Mask : ")) repeat i from 0 to 3 if i term.out("-") term.hex(byte[noparse][[/noparse]@stack][i],2) term.out(13) if settings.getData(settings#NET_IPv4_GATE,@stack,4) term.str(string("Gateway : ")) repeat i from 0 to 3 if i term.out("-") term.hex(byte[noparse][[/noparse]@stack][i],2) term.out(13) if settings.getData(settings#NET_IPv4_DNS,@stack,4) term.str(string("DNS : ")) repeat i from 0 to 3 if i term.out("-") term.hex(byte[noparse][[/noparse]@stack][i],2) term.out(13) ' lets start the nic services ' p0 = cs ' p1 = sck ' p2 = si ' p3 = so ' p4 = int ' p5 = *NOTHING CONNECTED* if not \nic.start(0, 1, 2, 3, 4, 5) term.str(string("Unable to start networking!")) waitcnt(clkfreq*10000 + cnt) reboot term.str(string("Networking Started")) term.out(13) term.str(string("Listening on port 80")) term.out(13) ' lets wait for a connetion repeat while \nic.listen(80) == -1 term.str(string("Connected!")) term.out(13) [/i][/i][/i][/i][/i]
Looking at the code for the
repeat while \nic.listen(80) == -1
it does not look like it blocks, hence the repeat...
All I have set my IP's...etc...
Thoughts?
~Kam (^8*
Comments
So do something like this:
EDIT: Changed writeByte example. I forgot it only writes one byte...
Post Edited (Harrison.) : 7/18/2008 12:47:17 AM GMT
Now it just sits and waits...
The plot thickens!
~Kam (^8*
Also, writeByte(...) only writes a single byte. You need api_telnet_serial.spin if you want to be able to use FullDuplexSerial style methods.
EDIT: You might want to add some more debug statements to see where it gets stuck.
Post Edited (Harrison.) : 7/18/2008 2:01:30 AM GMT
Well, smaller test program, same non-working issue
Here is the smaller code
Looking thru the code, it looks like it will use dhcp if we tell it *NOT* to use it...I think I did the setting correctly...
So I want my ip to be 10.200.1.142...
I have not change any code in the driver etc...
Any thoughts why it does not connect?
~Kam (^8*
You could also add a check to make sure nic.listen(80) returns a valid handle. You can check for negative values (socket allocation errors) or just call nic.isValidHandle(handle) to let the code do all the internal checks.
Well, no luck so far...I've had nothing but computer problems all day!
So this is my latest code, it connects to the network (should use dhcp)
I try to connect to http://74.125.19.104 (one of googles servers) and just print the recieved data
But nothing! BLA!
Here is the complete code...
Any thoughts people?
AAHHHHHHHHHHHHH
~Kam (^8*