Page 1 of 1

Send/ReceiveNetworkData() and delays

Posted: Mon Jun 23, 2003 3:17 am
by Karbon
Hello all. Just examining PB to see if I might be able to write a windows server in it.. Looks all good but my initial experiments left me a little confused about some things.

This is what i'm using in my server 's WaitWindowEvent() loop

Code: Select all

  Select NetworkServerEvent()
    
    Case 1

        AddGadgetItem(#Gadget_wnd_windowmain_ed_messages,-1,"User connection detected")

        ; User connected, display hello message.

        s_message.s = "Hello, welcome to the PB server! Yay!"
        
        SendNetworkData(NetworkClientID(), @s_message, Len(s_message)+1)
    
    Case 2
        
        AddGadgetItem(#Gadget_wnd_windowmain_ed_messages,-1,"New data detected")
        
       ; New data. Add it to our editor gadget.

        s_received_buffer.s = Space(512)
        
        ReceiveNetworkData(NetworkClientID(), @s_received_buffer, Len(s_received_buffer)+1)
    
        AddGadgetItem(#Gadget_wnd_windowmain_ed_messages,-1,s_received_buffer)

  EndSelect
And this is in the client..

Code: Select all

  Select NetworkClientEvent(l_conn_id)
    
    Case 2

        ; New data. Add it to our editor gadget.

        s_received_buffer.s = Space(512)
        
        ReceiveNetworkData(l_conn_id, @s_received_buffer, Len(s_received_buffer)+1)
    
        AddGadgetItem(#Gadget_wnd_windowmain_ed_messages,-1,s_received_buffer)
                
        
  EndSelect
What happens is that from the time the server sends it's little "Hello" message there is a 1- 5 second delay before I see it on the client side. I verified this with telnet so I'm pretty sure it's not anything I'm doing wrong in the client.. Is it some sort of windows buffering? Is there a way to flush those buffers so that data gets sent ASAP?

And one last thing.. In some network examples and older forum posts I'm seeing this but I'm not really sure what it gets me. If someone could explain the advantage this gives I'd appreciate it!

Code: Select all

#FD_ALL = #FD_READ|#FD_WRITE|#FD_OOB|#FD_ACCEPT|#FD_CONNECT|#FD_CLOSE
WSAAsyncSelect_(l_conn_id, WindowID(), #WM_NULL, #FD_ALL) 
Thanks!!

Re: Send/ReceiveNetworkData() and delays

Posted: Mon Jun 23, 2003 1:58 pm
by tinman
Karbon wrote:And one last thing.. In some network examples and older forum posts I'm seeing this but I'm not really sure what it gets me. If someone could explain the advantage this gives I'd appreciate it!

Code: Select all

#FD_ALL = #FD_READ|#FD_WRITE|#FD_OOB|#FD_ACCEPT|#FD_CONNECT|#FD_CLOSE
WSAAsyncSelect_(l_conn_id, WindowID(), #WM_NULL, #FD_ALL) 
It sends an event to your window when a network event occurs. That allows you to use WaitWindowEvent() and still find out about network events.

Posted: Mon Jun 23, 2003 4:58 pm
by Karbon
Hmm, I *think* I was using the exact same code in the waitwindowevent() loop with and without that .. I'll have to verify that in a few minutes..

Posted: Tue Jun 24, 2003 9:41 pm
by Karbon
It seems to work the same way with or without that code.. Anyway, what's with the delay I'm seeing? Buffering somewhere? Am I doing soemthing wrong in the way I'm sending/receiving?

Thanks!

<edit>

Must have been something stupid I was doing. Re-wrote things from scratch and the delay disappeared, no worries...