Shop OBEX P1 Docs P2 Docs Learn Events
Network Help — Parallax Forums

Network Help

Paul GPaul G Posts: 10
edited 2010-10-13 10:20 in Propeller 1
I am trying to use the PropTCP driver with a Gadget Gangster E-Net module. I have the demo webserver program running so I know the hardware works.

Ultimately what I want to do is to have the prop connect to a (PC based) server, send a piece text and read a valid / invalid result back from the server.

1) Is it possible to try and connect to an IP address and have it succeed or fail depending on whether there is a server listening or not ?

2) Am I using the correct unit for this (api_telnet_serial) or is there something more appropriate ?

3) Has anyone done this or can point me in the right direction or offer some sample code ?

Thanks

Paul

Comments

  • Paul GPaul G Posts: 10
    edited 2010-10-13 04:41
    OK, rather than ask such an open question, this is the code I am using to try and connect to a webserver that I know works. I cannot get a successful connection with it.

    Any help would be really appreciated.

    Paul
    CON
    _clkmode = xtal1+pll16x
    _xinfreq = 5_000_000
      rxlen = 128
      txlen = 2048
    
    OBJ
    
      lcd  : "serial_Lcd"                              ' Parallax Serial LCD Driver v1.2 
      kb   : "keyboard"
      enet : "api_telnet_serial"                      ' Ethernet module
    
    DAT
      mac_addr      byte    $02, $20, $00, $00, $00, $15    ' device mac address, must be unique
    
                    long
      ip_addr       byte    10, 0, 0, 252                   ' device's ip address
      ip_subnet     byte    255, 255, 255, 0                ' network subnet
      ip_gateway    byte    10, 0, 0, 250                 ' network gateway (router)
      ip_dns        byte    10, 0, 0, 250                 ' network dns
    
      ip_serv       byte    10, 0, 0, 250                    ' remote server for propeller client
      port_serv     byte    80                                 ' via telnet port
    
    VAR
      byte tcp_webrx1[rxlen]        ' buffers for socket 1
      byte tcp_webtx1[txlen]
      long ServerIP               ' remote server's IP, packed in a 32 bit number
      word ServerPort             ' remote server port number
        
    PUB main
    
      kb.start(26, 27) 'start the keyboard   
      enet.start(7, 6, 5, 4, -1, -1, @mac_addr, @ip_addr)
      
      LCD.init(8,9600, 4)
      LCD.cls 'Clear screen
      LCD.backlight(true) ' Backlight on  
      LCD.gotoxy(0, 0) ' Home position
      LCD.str(string("Trying to connect"))    
    
      ServerIP := (byte[@ip_serv]<<24)+(byte[@ip_serv+1]<<16)+(byte[@ip_serv+2]<<8)+byte[@ip_serv+3]
      ServerPort := byte[@port_serv]
    
      enet.connect(ServerIP, ServerPort, @tcp_webrx1, rxlen, @tcp_webtx1, txlen)
      enet.resetBuffers
      enet.WaitConnectTimeout(2000)
    
      LCD.cls 'Clear screen
      LCD.gotoxy(0, 0) ' Home position
    
      if enet.IsConnected
        LCD.str(string("Success"))
      else
        LCD.str(string("CONNECTION FAILED"))    
      REPEAT
        LCD.putc(kb.getkey) 
    
  • Paul GPaul G Posts: 10
    edited 2010-10-13 08:38
    OK, it seems the problem is that the connection does not get established the first time through the program. I changed the code so that

    a) There was a delay between calling the .start method and the .connect method

    b) The .connect method is within the loop of the program so that pressing a key will re-try the connection.

    Now, the first connection attempt invariably fails but subsequent attempts (mostly) work fine.
  • tdlivingstdlivings Posts: 437
    edited 2010-10-13 08:53
    At the end of your code you check if enot.IsConnected only once which happens in a flash. Seems like you should loop watching for a period of time for a connection and fall out of the loop if successfull connection or fail if time out and no connection yet.

    Tom
  • Paul GPaul G Posts: 10
    edited 2010-10-13 10:20
    tdlivings wrote: »
    At the end of your code you check if enot.IsConnected only once which happens in a flash. Seems like you should loop watching for a period of time for a connection and fall out of the loop if successfull connection or fail if time out and no connection yet.

    Tom

    As I understand the code, the enet.WaitConnectTimeout(2000) loops until either the connection is made or the timeout (of 2000 mS) elapses. I have tried longer values without success.

    Once the initial failure is out of the way, the connection occurs virtually immediately.

    Paul
Sign In or Register to comment.