Send/ReceiveNetworkData() and delays

Windows specific forum
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Send/ReceiveNetworkData() and delays

Post 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!!
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Re: Send/ReceiveNetworkData() and delays

Post 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.
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post 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..
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post 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...
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Post Reply