Transmitting files across the network

Previous topic - Next topic

FutureCow

Has anyone got a better solution for transmitting files than
SENDING END
* Do 1023 READUBYTE commands, and append the result each time to a transmission string
* send the string via NETSENDMSG.
* Write some sort of EOF string to the buffer

RECEIVING END
* receive the string with NETGETMSG
* Append the string to the destination file with WRITEUBYTE
* stop reading when EOF string read

I haven't tried it yet, but I'm not a fan of trying to encode a binary file as a string - particularly as I think I'm likely to run into typecasting errors.

Any thoughts anyone?

Moru

I'm not sure but I think I tried sending data as binary over the network... I'll try to dig out the code again and test it with the new netcode. Only trouble I can imagine is the byte 0, the rest is just a character in the chartable so should work.

Kitty Hello

You can put chr$(0) in a string in GLBasic!! You can have binary data in a string.
If you transfer it over the network (use SOCK_ here) you'd better write a tiny header (filetype and length) and then the data.

FutureCow

I hadn't looked at SOCK_ yet, I'd been looking at NET_

What's the maximum length (would be handy to have in the docs  :whip: ;) ) that you can send with SOCK_TCPSEND?

Kitty Hello

sock_tcpsend has no limit. The NET commands are limited to ... uhm... 1024 bytes.. maybe?

FutureCow

So is there any reason I wouldn't want to send say a 1MB file as 1 SOCK_TCPSEND command? What would you consider "best practice?"

Though I suppose doing this there would be no way to show how much has been transferred (ie. 1% done, 2% done ... etc)

Moru

There is a limit on how big packets some routers can transfer, keep the size below 1540 at least, 1024 is probably safer :)

Kitty Hello

Take a look at my Network for cowards tutorials, where I upload a file to a webserver running php. That's exaclty what you want.

Moru

#8
Not all routers can chop up packets reliably, that's why I say to keep the size down if you are not programming only for yourself.

Are you planning on transfering between two GLBasic applications on the same network or do you want to transfer over the internet to a webserver for access later or what are you trying to do?

kaotiklabs

Just for info:
You are talking about MTU ( Maximum transmission unit).
And as was said, the MTU for Ethernet v2 is 1500 bytes.

Just for compatibility issues and safety usually is configured to 1492 bytes that is the MTU for Ethernet (802.3).
Vote Cthulhu! Because the stars are right!!!!
Ia Ia Cthulhu F' tang!

Moru

Yes but most equipment can handle bigger by splitting packets and assembling these on the other hand. This should all be taken care of outside of our control.

kaotiklabs

Yes.
Thi bigger packets, out of rfc, as far as I can remember, are called jumbo frames.

But as you said, only should be used on controlled environments.
Vote Cthulhu! Because the stars are right!!!!
Ia Ia Cthulhu F' tang!

FutureCow

#12
I'm actually a Unix admin by trade, so I'm well aware of MTUs, packet reassembly etc. What I'm not aware of is the black magic happening in the background (ie. what GLBasic actually does when you use that command) - hence the question. There would be no point chopping your data into chunks if the command was doing that itself in the background.

I'll stick to 1024 bytes I think, that's a convenient number, and besides which it makes it easy to do a "number of KB uploaded" counter.

Kitty Hello/Moru : I had a look at your tutorials (they're what I've been working off) but they deal with transmitting files to a webserver. I'm doing GLBasic application to another copy of the same program elsewhere on the network/internet (ie. sharing game data between two people playing the same game). There's no reason I can see that players should have to run a webserver.

Kitty Hello

I have a webserver (mini mini) in GLBasic, somewhere, too... Wait..
Code (glbasic) Select

// Simple "web" server program to interact with a browser

GLOBAL WEB_port% = 11111

SOCK_INIT()

LOCAL sock_listen% = SOCK_TCPLISTEN(WEB_port%)
WHILE TRUE
LOCAL cl_ip%
LOCAL client% = SOCK_TCPACCEPT(sock_listen%, cl_ip%)
IF client% <> -1

STDOUT "Connection\n"
LOCAL rv%, msg$
LOCAL full$
WHILE TRUE
rv% = SOCK_RECV(client%, msg$, 1024)
IF rv = 0 THEN GOTO client_quit

INC full$, msg$
IF rv%<1024 THEN BREAK
WEND
STDOUT "Full Message:\n" + full$+"\n\n"

SendMessage(client%, "<html><body><h1>HELLO WORLD</H1></body></html>")
SOCK_CLOSE(client) // no keep-alive connection, K

ENDIF
client_quit:


WEND


FUNCTION Http_TextArea: varname$
// TODO


ENDFUNCTION




FUNCTION SendMessage: sock%, postdata$
LOCAL send$
send$ = "HTTP/1.0 200 OK\r\n"
INC send$, "Date: "+PLATFORMINFO$("DATE")+" "+PLATFORMINFO$("TIME")+"\r\n"
INC send$, "Content-Type: text/html\r\n"
INC send$, "Content-Length: "+LEN(postdata$) + "\r\n"
INC send$, "\r\n"
INC send$, postdata$

SOCK_TCPSEND(sock%, send$)

ENDFUNCTION


No magic.

FutureCow

NO magic? :nw: EVERYTHING you do is magic Gernot!  =D