Author Topic: send file?[BB2D]  (Read 9158 times)

0 Members and 3 Guests are viewing this topic.

Offline Paul

  • Pentium
  • *****
  • Posts: 1490
  • Karma: 47
    • View Profile
send file?[BB2D]
« on: January 05, 2007 »
Hello!

Is it possible for blitz to send a file from 1 computer to an other?
If so how?

i'm thinking encoding the file with a 64 bit encoder, sending it and then decoding it but that would be verry inefficient.

 
« Last Edit: July 21, 2007 by Shockwave »
I will bite you - http://s5.bitefight.se/c.php?uid=31059
Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: send file?
« Reply #1 on: January 05, 2007 »
Yep, blitz can send data using TCP or UDP. For sending a file use TCP, look up TCP(network) in the command docs as there should be some small examples there.

Offline Paul

  • Pentium
  • *****
  • Posts: 1490
  • Karma: 47
    • View Profile
Re: send file?
« Reply #2 on: January 05, 2007 »
isnt that just gor sending text?
i mean for sending an image or an exe file
I will bite you - http://s5.bitefight.se/c.php?uid=31059
Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: send file?
« Reply #3 on: January 05, 2007 »
It can be used to send data of any type, not only strings. Look up readint/writeint, also for bytes or floats.

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: send file?
« Reply #4 on: January 05, 2007 »
I think that Blitz Plus has much more features for using web based stuff.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: send file?
« Reply #5 on: January 05, 2007 »
The basic networking stuff on both are the same afaik but is there anything else in blitzplus that would be of use here?
« Last Edit: January 05, 2007 by Stonemonkey »

Offline Paul

  • Pentium
  • *****
  • Posts: 1490
  • Karma: 47
    • View Profile
Re: send file?
« Reply #6 on: January 05, 2007 »
If i forexample want to send an exe file to an other computer how would i do???
I will bite you - http://s5.bitefight.se/c.php?uid=31059
Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: send file?
« Reply #7 on: January 05, 2007 »
You'll need to open a TCP stream between the 2 machines, can't really remember how to do that atm but once they're connected:

the source machine sends the name (and type) of the file you're wanting to send then opens the file and reads and sends all the data from that file

while the destination machine recieves that data and saves it to disk using the filename/type it recieved.

While you're working on this, instead of trying to get it working using 2 machines you can use the loopback ip address 127.0.0.1 and have the client/server both running on 1 machine.

Offline Paul

  • Pentium
  • *****
  • Posts: 1490
  • Karma: 47
    • View Profile
Re: send file?
« Reply #8 on: January 05, 2007 »
just one thing.
do i use readline, readstring or read what??
I will bite you - http://s5.bitefight.se/c.php?uid=31059
Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: send file?
« Reply #9 on: January 05, 2007 »
I would probably use write/readstring to send the filename and then send the file data as bytes although i think i've read somehwere that it's faster to put bytes into a string and send that but tbh it's been a while since i've done anything like this.

Offline Paul

  • Pentium
  • *****
  • Posts: 1490
  • Karma: 47
    • View Profile
Re: send file?
« Reply #10 on: January 05, 2007 »
Its working :)

Code: [Select]
; 1 st code set
server=CreateTCPServer(8080)
If server=0 Then Print ":(" WaitKey():End
Print "server started"
Print "waiting"
While Not stream
stream=AcceptTCPStream(server)
Wend
Print "connected"
file=WriteFile(ReadString$(stream))
Print "reciving file"
While Not KeyHit(1)

If Not Eof(stream)
WriteByte(file,ReadByte%(stream))
Else
Print "done"
CloseFile(file)
WaitKey()
End
EndIf

Wend
CloseFile(file)
End

Code: [Select]
;2nd code
server=OpenTCPStream("192.168.0.2",8080)

If server=0 Then Print ":(" WaitKey():End
file=OpenFile("C:\Documents and Settings\david1.DAVID\Desktop\paul\meny.bmp");<-- change this to your image( or ;other file
WriteString(server,"meny.bmp")<--And this
Print "sending"
While Not KeyHit(1)
If Not Eof(file)
WriteByte(server,ReadByte%(file))
Else
Print "done"
EndIf
Wend

Quote
i've read somehwere that it's faster to put bytes into a string

how long can a string be?

Thx for the help Stonemonkey :D .)
« Last Edit: January 09, 2007 by Clyde »
I will bite you - http://s5.bitefight.se/c.php?uid=31059
Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: send file?
« Reply #11 on: January 05, 2007 »
Good work paul, I'm not sure about the string length but i'd put some sort of limit on it.

Offline Paul

  • Pentium
  • *****
  • Posts: 1490
  • Karma: 47
    • View Profile
Re: send file?
« Reply #12 on: January 06, 2007 »
Just want to post the finished code :) or well a working code. i've done a function that doesn't return until the file is sent but it will show ny1 how th do. hope someone find it useful

Code: [Select]
Select recivefile()
Case  1: Print "Sucess"
Case  0: Print "unknown???"
Case -1: Print "Time out"
Case -2: Print "unable to write file"
Case -3: Print "file my be dead"
End Select
WaitKey()

Edit:
forgot to say there is  bug somewhere, the file gets a little bit bigger for some reason...

Code: [Select]
Function recivefile()
server=CreateTCPServer(8080)
If server=0 Then Return 0
;Print "server started"
;Print "waiting"
While Not stream
tmp=tmp+1
stream=AcceptTCPStream(server)
Delay 100
If tmp>600 Then Return -1
Wend
;Print "connected"
file=WriteFile(ReadString$(stream))
If file=0 Then Return -2
;Print "reciving file"
Print "Recieving Mr.file"
Repeat
If Not Eof(stream)
tmpo$=ReadString$(stream)
For i=0 To 1024
tmp2$=Mid$(tmpo$,(i+1)*3,3)
; Print tmp2$:WaitKey():End
If tmp2$="sto" Then Exit
WriteByte(file,tmp2$)
Next
wistro=wistro+1
Print wistro
Else
If file<>0
CloseFile(file)
Return 1
EndIf
Return -3
EndIf
Forever
End Function

;***********************************************
;***********************************************
;***********************************************
;***********************************************
;***********************************************
;***********************************************

Select sendfile("C:\Documents And Settings\david1.DAVID\Desktop\paul\","MUSIC9.MID","hubba.mid","127.0.0.1");"192.168.0.2")
Case  1: Print "sucess"
Case  0: Print "unknown???"
Case -1: Print "Time out"
Case -2: Print "unable to read file"
Case -3: Print "unknown???"
End Select
WaitKey()

Function sendfile(path$,name$,dname$,ip$)
Repeat
server=OpenTCPStream(ip$,8080);"192.168.0.2"
Delay 100
a=a+1
Print a
Forever
If server = 0 Then Return -1
file=OpenFile(path$+name$)
If file   = 0 Then Return -2

WriteString(server,dname$)
Print "sending"

Repeat
If Not Eof(file)
tmp$="aa"
For i=0 To 1024
tmp2$=ReadByte%(file)

If Eof(file) tmp$=tmp$+"sto":Exit
;Print tmp$+String("0",(3-Len(tmp2$)))+tmp2$
tmp$=tmp$+String("0",(3-Len(tmp2$)))+tmp2$
If i=1 Then tmp3$=tmp$
Next

tmpas=tmpas+1
Print tmpas
WriteString(server,tmp$)
;Print tmp3$ WaitKey():End
;Delay 100
Else
If server<>0
CloseTCPStream(server)
Return 1
Else
Return -3
EndIf
EndIf
Forever
End Function
« Last Edit: January 09, 2007 by Clyde »
I will bite you - http://s5.bitefight.se/c.php?uid=31059
Challenge Trophies Won:

Offline mike_g

  • Amiga 1200
  • ****
  • Posts: 435
  • Karma: 34
    • View Profile
Re: send file?
« Reply #13 on: January 06, 2007 »
Cool, I havent worked with any of the Blitz networking commands yet so I'll check this out and try learn something new :)

Offline Paul

  • Pentium
  • *****
  • Posts: 1490
  • Karma: 47
    • View Profile
Re: send file?
« Reply #14 on: January 09, 2007 »
Hi again

There is a problem with the above code, It doesn't work online, only lan. atleast for me. if anyone finds the problem (or a fix) please tell me. Or if it works for someone else .
I will bite you - http://s5.bitefight.se/c.php?uid=31059
Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: send file?
« Reply #15 on: January 09, 2007 »
Ah, I had the same problem when i replaced my modem with a router and I don't think I found a solution but there must be something that can be done.

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: send file?
« Reply #16 on: January 09, 2007 »
Quote
There is a problem with the above code, It doesn't work online, only lan. atleast for me. if anyone finds the problem (or a fix) please tell me. Or if it works for someone else .
It won't work if both ends are using NAT (Network Address Translation), the same way that BitTorrent or eDonkey goes into passive mode and you can't hardly see anyone.  One end needs to un-NAT (turn the NAT router into a bridge, perhaps you have menu option on the router) or both ends need to use uPNP to set up a connection.  Whether uPNP's possible from blitz I wouldn't know, probably not.  Be careful turning off NAT though, it leaves your computer wide open to the net unless you have a good software firewall (NOT Windows firewall as it doesn't block incoming connections).

Something else to try.  Enable port forwarding on your router for the port number you are using (should be > 49151) so when your friend tries to send you a file, it gets directed to the correct computer on your LAN.  This is how you enable BitTorrent etc to work properly.

Jim
« Last Edit: January 09, 2007 by Jim »
Challenge Trophies Won:

Offline Paul

  • Pentium
  • *****
  • Posts: 1490
  • Karma: 47
    • View Profile
Re: send file?
« Reply #17 on: January 11, 2007 »
So in simpler terms you're saying that my friends router firewall is blocking me?
I will bite you - http://s5.bitefight.se/c.php?uid=31059
Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: send file?
« Reply #18 on: January 11, 2007 »
It's more to do with how the router knows which address on the LAN that the data is meant to be going to, the IP that you try to connect to will just be the address of the router on the internet and setting up port forwarding for a particular port number will tell the router which address on the LAN that the data coming in on that port is meant for.

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: send file?
« Reply #19 on: January 11, 2007 »
Quote
So in simpler terms you're saying that my friends router firewall is blocking me?

The problem is NAT.

All traffic from a LAN which is connected to the net by a NAT router appears to the outside world to come from the router.  When someone tries to talk to you from outside they only talk to the router.  This means if the router has not been told where to direct that traffic it will be dropped.  The way to fix this is port forwarding.  When someone connects to your router on a given port number (you chose 8080) then you need to tell your router (using its configuration panel) to forward any traffic on that port to a specific IP address on your LAN.

As you can see, NAT is also a pretty good security feature.  Your router drops all unforwarded inbound traffic as if your LAN didn't exist.

Btw, you shouldn't use port 8080, it's registered already as being used for HTTP traffic.  If your message goes via a proxy server (anywhere along the way) it might get corrupted or dropped unless it actually looks like http.
You should use a port above 49151.
Port numbers can be found here http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers

Jim
« Last Edit: January 11, 2007 by Jim »
Challenge Trophies Won: