Page 1 of 1

Posted: Wed Dec 25, 2002 1:38 pm
by BackupUser
Restored from previous forum. Originally posted by pbdep.


Hiya all,

I dont seem to be able to get ReceieveNetworkFile to work.
Well its executed (seen by debugging) but NO file is saved.

So im wondering, Is it working ? Should A file be opened/created
first befor using Receivenetworkfile?

Any hint would do :wink:

Merry Xmas...

Norman.

Posted: Thu Dec 26, 2002 12:45 pm
by BackupUser
Restored from previous forum. Originally posted by tranquil.

Better use SendNetworkData and ReveiveNetworkData if you are using the Linux Version of PB. In win32 case you should use the WinAPI instead.

Dont forget to do a errorhandling. Most of the Sourcecodes shown here in the forum does not and that may couse in loose of datas.

There are some x-amples posted some time ago in the Tips & Tricks section.

Happy X-Mass!

Cheers
Mike

Tranquilizer/ Secretly!
http://www.secretly.de
Registred PureBasic User
System: Windows 2000 Server, 512 MB Ram, GeForce4200 TI 128 MB DDR, Hercules Theater 6.1 DTS Sound

Posted: Thu Dec 26, 2002 2:13 pm
by BackupUser
Restored from previous forum. Originally posted by pbdep.
Originally posted by tranquil

Better use SendNetworkData and ReveiveNetworkData if you are using the Linux Version of PB. In win32 case you should use the WinAPI instead.

Dont forget to do a errorhandling. Most of the Sourcecodes shown here in the forum does not and that may couse in loose of datas.

There are some x-amples posted some time ago in the Tips & Tricks section.

Happy X-Mass!

Cheers
Mike

Tranquilizer/ Secretly!
http://www.secretly.de
Registred PureBasic User
System: Windows 2000 Server, 512 MB Ram, GeForce4200 TI 128 MB DDR, Hercules Theater 6.1 DTS Sound
Hi Tranquil,

Yes I did rebuild my program to use ReceiveNetworkData,
I did not know if Send/ReceieveNetworkFile was working at all
because I did not see a thing using tcpdump.

The only errorchecking I can think of is the checking of
local and remote socket hungups the rest is upto TCP, okay
i could do some packet counting but TCP is no UDP :wink:

Im not sure how the Sockets where implmented but i may assume
that they do Re-sent on errors ?? Otherwise you have to rebuild
the Sending and receiving of data packets by ACK/NACK handling
of packets while sending or receiving, creates overhead in the
program.

Perhpas Fred could tell us a little more on the SendNetworkFile
function, how it is done :wink: Im too lazy debugging the network
stack right now ..heheh..

Merry Xmas to u too.. :)

Norman.

Posted: Thu Dec 26, 2002 4:09 pm
by BackupUser
Restored from previous forum. Originally posted by tranquil.

If you send files to the TCP/IP Buffer (large ones) and the TCP/IP buffer is full couse your internet or lan connection could not process the datas as fast as your application sends it, you have to resend the datas some msecs later.
SendNetworkData() returns the amount of bytes send by TCP/IP. If there is a problem during that there is a #SOCKET_ERROR reported.
Tha API command wsagetlasterror_() reports the error detail which can be one of the following:
If wsaerror=#WSANOTINITIALISED:err$="Wsa not initialized":EndIf
If wsaerror=#WSAENETDOWN :err$="The Windows Sockets implementation has detected that the network subsystem has failed.":EndIf
If wsaerror=#WSAENOTCONN :err$="Socket not connected.":EndIf
If wsaerror=#WSAEINTR :err$="The (blocking) call was canceled using WSACancelBlocking":EndIf
If wsaerror=#WSAEINPROGRESS :err$="A blocking Windows Sockets operation is in progress.":EndIf
If wsaerror=#WSAENOTSOCK :err$="The descriptor is not a socket.":EndIf
If wsaerror=#WSAEOPNOTSUPP :err$="MSG_OOB was specified, but the socket is not of type SOCK_STREAM.":EndIf
If wsaerror=#WSAESHUTDOWN :err$="The socket has been shut down; it is not possible to recv on a socket after shutdown has been invoked with how set to 0 or 2.":EndIf
If wsaerror=#WSAEMSGSIZE :err$="The datagram was too large to fit into the specified buffer and was truncated.":EndIf
If wsaerror=#WSAEINVAL :err$="The socket has not been bound with bind.":EndIf
If wsaerror=#WSAECONNABORTED :err$="The virtual circuit was aborted due to timeout or other failure.":EndIf
If wsaerror=#WSAECONNRESET :err$="The virtual circuit was reset by the remote side.":EndIf
If wsaerror=#WSAEWOULDBLOCK :err$="The socket is marked as nonblocking":EndIf
If wsaerror=#WSAEWOULDBLOCK:send=0:sended=0:Delay(250):EndIf

#WSAEWOULDBLOCK is the most importend. This is reported when the TCP/IP Buffer is full or can not process your datas yet. Only wait a short time and try again.


Same thingie on ReceiveNetworkData. Its STRONGLY recommanded that you check, how many bytes are receives with ReceiveNetworkdata().
ReceiveNetworkdata() Returns the number of bytes received. This can be another amount of bytes then the SendNetworkData().

Eg.: You call SendnetworkData() with sending 20 Bytes.
The first call of receivenetworkdata() receives the first 15 Bytes (couse the rest of 5 bytes cames with another TCP/IP Packet and tackes a bit longer) you have to call receivenetworkdata() again and again till your datapacket is complete.

On Serversides you need a Buffer for every connected Socket for completing your Datapackets.

Hope that helpes a bit.

Tranquilizer/ Secretly!
http://www.secretly.de
Registred PureBasic User
System: Windows 2000 Server, 512 MB Ram, GeForce4200 TI 128 MB DDR, Hercules Theater 6.1 DTS Sound
System 2: Mobile Pentium 4 2.4GHz 512 MB DDR GeForce4 420-32, Windows XP Home

Posted: Thu Dec 26, 2002 6:28 pm
by BackupUser
Restored from previous forum. Originally posted by pbdep.
Originally posted by tranquil

If you send files to the TCP/IP Buffer (large ones) and the TCP/IP buffer is full couse your internet or lan connection could not process the datas as fast as your application sends it, you have to resend the datas some msecs later.
SendNetworkData() returns the amount of bytes send by TCP/IP. If there is a problem during that there is a #SOCKET_ERROR reported.
Tha API command wsagetlasterror_() reports the error detail which can be one of the following:
If wsaerror=#WSANOTINITIALISED:err$="Wsa not initialized":EndIf
If wsaerror=#WSAENETDOWN :err$="The Windows Sockets implementation has detected that the network subsystem has failed.":EndIf
If wsaerror=#WSAENOTCONN :err$="Socket not connected.":EndIf
If wsaerror=#WSAEINTR :err$="The (blocking) call was canceled using WSACancelBlocking":EndIf
If wsaerror=#WSAEINPROGRESS :err$="A blocking Windows Sockets operation is in progress.":EndIf
If wsaerror=#WSAENOTSOCK :err$="The descriptor is not a socket.":EndIf
If wsaerror=#WSAEOPNOTSUPP :err$="MSG_OOB was specified, but the socket is not of type SOCK_STREAM.":EndIf
If wsaerror=#WSAESHUTDOWN :err$="The socket has been shut down; it is not possible to recv on a socket after shutdown has been invoked with how set to 0 or 2.":EndIf
If wsaerror=#WSAEMSGSIZE :err$="The datagram was too large to fit into the specified buffer and was truncated.":EndIf
If wsaerror=#WSAEINVAL :err$="The socket has not been bound with bind.":EndIf
If wsaerror=#WSAECONNABORTED :err$="The virtual circuit was aborted due to timeout or other failure.":EndIf
If wsaerror=#WSAECONNRESET :err$="The virtual circuit was reset by the remote side.":EndIf
If wsaerror=#WSAEWOULDBLOCK :err$="The socket is marked as nonblocking":EndIf
If wsaerror=#WSAEWOULDBLOCK:send=0:sended=0:Delay(250):EndIf

#WSAEWOULDBLOCK is the most importend. This is reported when the TCP/IP Buffer is full or can not process your datas yet. Only wait a short time and try again.


Same thingie on ReceiveNetworkData. Its STRONGLY recommanded that you check, how many bytes are receives with ReceiveNetworkdata().
ReceiveNetworkdata() Returns the number of bytes received. This can be another amount of bytes then the SendNetworkData().

Eg.: You call SendnetworkData() with sending 20 Bytes.
The first call of receivenetworkdata() receives the first 15 Bytes (couse the rest of 5 bytes cames with another TCP/IP Packet and tackes a bit longer) you have to call receivenetworkdata() again and again till your datapacket is complete.

On Serversides you need a Buffer for every connected Socket for completing your Datapackets.

Hope that helpes a bit.

Tranquilizer/ Secretly!
http://www.secretly.de
Registred PureBasic User
System: Windows 2000 Server, 512 MB Ram, GeForce4200 TI 128 MB DDR, Hercules Theater 6.1 DTS Sound
System 2: Mobile Pentium 4 2.4GHz 512 MB DDR GeForce4 420-32, Windows XP Home

Hi Tranquil,

Oke so PB does not make use of Layer3/4 packet checking in TCP?

Well that makes programming a little irritating because people
should buildin there own CRC and also there own Packet-Counter.
(This sounds like pure UDP protocol, but then over TCP :-!)

Anyway.. I agree with you on the IO buffering, I use a delay
between MemoryCopy (IO buffer and Socket Buffer) and for
failsave options I use a PacketCounter (ACK/NACK on packets).

But this should not be the case with good Socket implementation,
Because the Network Functions should have there own Buffering!!!
That buffering should be dynamic, which meens that Network functions
control the buffering regarding the demand on IO data and will
enlarge the buffer if needed for a spool..

MMm I think Fred should bring some light into the darkness
on How networking is implmented in PB, make talking about it
a little better :wink:

Regards,
Norman.

Posted: Thu Dec 26, 2002 9:41 pm
by BackupUser
Restored from previous forum. Originally posted by tranquil.

PB handles Networking as Windows API do. There is no difference to Visual Basic or C.

CRC isnt needed couse TCP/IP will request a damaged Datapacket automatically. If you do an error handling everything is okay and works in PB. The only hazle in PB is the network event handling. Without Windows API its not possible yet.

Mike

Tranquilizer/ Secretly!
http://www.secretly.de
Registred PureBasic User
System: Windows 2000 Server, 512 MB Ram, GeForce4200 TI 128 MB DDR, Hercules Theater 6.1 DTS Sound
System 2: Mobile Pentium 4 2.4GHz 512 MB DDR GeForce4 420-32, Windows XP Home