Page 1 of 1
					
				Networking question
				Posted: Thu Jan 16, 2014 10:52 am
				by sirrab
				Hi All,
I hope someone can help me as this is driving me nuts 
I am writing a program that accesses a server. when I use telnet and enter the commands no worries it works. But if I send the commands using sendnetworkstring or sendnetworkdata with chr(10) and chr(13) on the end nothing. is there something about pb that could be causing this? I cant really ask the creater of the server as I can't get into there yahoo group and there docs are a joke !
Any ideas very welcome 
Craig
 
			 
			
					
				Re: Networking question
				Posted: Thu Jan 16, 2014 2:28 pm
				by swhite
				Perhaps you could post your code so we can see what you are doing.
Simon
			 
			
					
				Re: Networking question
				Posted: Thu Jan 16, 2014 9:07 pm
				by sirrab
				My code as requested 
Code: Select all
If InitNetwork() = 0
  MessageRequester("Error", "Can't initialize the network !", 0)
  End
EndIf
dccserver =  OpenNetworkConnection("192.168.1.23",3246,#PB_Network_TCP)
Procedure receivedata(dccserver,waitfor$)
  *Buffer = AllocateMemory(1000)
  dsize = 100
  If NetworkClientEvent(dccserver) = #PB_NetworkEvent_Data      
    
    FreeMemory(*Buffer)
    *Buffer = AllocateMemory(1000)
  dsize = ReceiveNetworkData(dccserver, *Buffer,1000)
  ;dsize = Len(PeekS(*Buffer))
  
  ;Debug dsize
  ;Debug PeekS(*Buffer)
 
 EndIf
  FreeMemory(*Buffer)
EndProcedure
Procedure senddata(dccserver,datatosend$)
  
    *sendbuffer = AllocateMemory(Len(datatosend$) + 1)
    PokeS(*sendbuffer,datatosend$)
    ; SendNetworkData(dccserver,*sendbuffer  ,Len(datatosend$))  
    SendNetworkString(dccserver,datatosend$)
    FreeMemory(*sendbuffer)
    
EndProcedure
ce$ = Chr(13) + Chr(10)
dccserver =  OpenNetworkConnection("192.168.1.23",3246,#PB_Network_TCP)
If dccserver
  
  receivedata(dccserver,"PW12080")
  
    senddata(dccserver,"N1234" + ce$) 
    
    
    senddata(dccserver,"TL2836")
  
  CloseNetworkConnection(dccserver) 
  
  EndIf
 
			 
			
					
				Re: Networking question
				Posted: Thu Jan 16, 2014 10:24 pm
				by netmaestro
				Call NetworkClientEvent() in a loop to wait until you receive something. Calling it just the once won't work.
			 
			
					
				Re: Networking question
				Posted: Fri Jan 17, 2014 5:51 am
				by sirrab
				Thanks for the reply netmaestro,
I tried that but no luck. Its like the enter key needs to be pressed. I have tried it with chr(13) added as well as chr(10) and combinations of both. Anyone know what pressing enter in telnet sends?
Thanks Craig
			 
			
					
				Re: Networking question
				Posted: Fri Jan 17, 2014 8:01 am
				by infratec
				Hi,
try this:
Code: Select all
EnableExplicit
Procedure.i receivedata(dccserver.i, waitfor$)
  
  Protected Result.i, dsize.i, *Buffer, Rcv$
  
  
  *Buffer = AllocateMemory(1000)
  If *Buffer
    
    PokeS(*Buffer, waitfor$, -1, #PB_UTF8)
    waitfor$ = PeekS(*Buffer, -1, #PB_UTF8)
    
    Repeat
      If NetworkClientEvent(dccserver) = #PB_NetworkEvent_Data     
        
        dsize = ReceiveNetworkData(dccserver, *Buffer, 1000)
        If dsize
          Debug dsize
          Rcv$ = PeekS(*Buffer, dsize, #PB_UTF8)
          Debug Rcv$
          If Rcv$ = waitfor$
            Result = #True
          EndIf
        EndIf
      Else
        Delay(10)
      EndIf
    Until Result
    
    FreeMemory(*Buffer)
  EndIf
  
  ProcedureReturn Result
  
EndProcedure
Define.i dccserver
If InitNetwork() = 0
  MessageRequester("Error", "Can't initialize the network !", 0)
  End
EndIf
dccserver =  OpenNetworkConnection("192.168.1.23", 3246, #PB_Network_TCP)
If dccserver
  
  receivedata(dccserver, "PW12080")
  
  SendNetworkString(dccserver,"N1234" + #CRLF$, #PB_UTF8)
  SendNetworkString(dccserver,"TL2836", #PB_UTF8)
  
  CloseNetworkConnection(dccserver)
Else
  MessageRequester("Error", "Was not able to connect.")
EndIf
Bernd
 
			 
			
					
				Re: Networking question
				Posted: Tue Jan 21, 2014 5:04 am
				by sirrab
				Hi Al, sorry about not replaying sooner.
Thanks for all the ideas, no luck with though 
Craig
 
			 
			
					
				Re: Networking question
				Posted: Tue Feb 04, 2014 3:08 am
				by RichAlgeni
				Did you ever get this working?
			 
			
					
				Re: Networking question
				Posted: Sun Feb 09, 2014 10:20 am
				by sirrab
				Sorry about the delay in replying. No I haven't got it working. Been a bit busy of late. will have to try and have a play with it this week ! 
Craig
 
			 
			
					
				Re: Networking question
				Posted: Sun Feb 09, 2014 10:52 pm
				by RichAlgeni
				In your procedure below, you have the 
#PB_NetworkEvent_Data check, but you only do it once. If there isn't data in the network receive buffer, the 
#PB_NetworkEvent_Data check will fail. Your code will continue after the 
EndIf statement, where the procedure will end. You need loop statement to check 
#PB_NetworkEvent_Data again, and a short delay to wait until your next attempt. You also need some sort of loop counter, so that if nothing is received with a reasonable amount of time, your loop can end with some sort of error message.
Code: Select all
Procedure receivedata(dccserver,waitfor$)
  *Buffer = AllocateMemory(1000)
  dsize = 100
  If NetworkClientEvent(dccserver) = #PB_NetworkEvent_Data
    FreeMemory(*Buffer)
    *Buffer = AllocateMemory(1000)
  dsize = ReceiveNetworkData(dccserver, *Buffer,1000)
  ;dsize = Len(PeekS(*Buffer))
    ;Debug dsize
  ;Debug PeekS(*Buffer)
  EndIf
  FreeMemory(*Buffer)
EndProcedure
There are many ways to accomplish what you need, with Infratec's being a good example. If you are serious about learning to code, I along with others will be glad to help you. The first thing I'd recommend is to download and read Kale's book! The second thing is to always use 
EnableExplicit.