tcp/ip exe transfer
Blitz3D Forums/Blitz3D Beginners Area/tcp/ip exe transfer
| ||
I tryed to transfer two file with the tcp/ip commands of Blitz3D. I can't transfer an exacutable file from one computer to another. In wich way can i do it? |
| ||
something like this, g2g nowbla = readfile("sdfds.exe") while not eof(bla) WriteByte tcp,readbyte(bla) wend |
| ||
I tryed it, but it copy only 1 byte... This is the code: ;Listener(receive file) svrcom=CreateTCPServer(9015) If svrcom<>0 Then Print "Server started successfully." Else Print "Server failed to start." End End If While Not KeyHit(1) strstream=AcceptTCPStream(svrcom) If strstream Then Print ReadString$(strstream) WaitKey() End Else Print "Attempting messages..." Delay 1000 End If Wend End ;Server(send file) strmcom=OpenTCPStream("127.0.0.1",9015) file = ReadFile("agent.exe") fileout=ReadFile("agent2.exe") If strmcom<>0 Then Print "Client Connected successfully." Else Print "Server failed to connect." WaitKey End End If While Not Eof(file) linea = ReadByte( file ) WriteByte(strmcom,linea) Wend CloseFile( file ) CloseFile(fileout) Print "Completed sending message..." |
| ||
Srry but I don't have the time today to write the code. Check this (Code archives) http://www.blitzbasic.com/codearcs/codearcs.php?code=487 Or "ftp" http://www.blitzbasic.com/codearcs/codearcs.php?code=16 |
| ||
Are you sure the Server is not closeing the connection before the client reads the data? |
| ||
I'm trying the file on the same computer. |
| ||
this is your client code:svrcom=CreateTCPServer(9015) If svrcom<>0 Then Print "Server started successfully." Else Print "Server failed to start." End End If While Not KeyHit(1) strstream=AcceptTCPStream(svrcom) If strstream Then Print ReadString$(strstream) WaitKey() End Else Print "Attempting messages..." Delay 1000 End If Wend End the problem is.. it's not creating a file.. its not saving any information. A TCP stream isn't like HTTP browsing a website.. you have to read and write every byte to a file manually.. First of all you have to have a handshake connection where the server tells the client that it's trying to send a file, and what it's name is - then the client has to open a new file under that name, and start reading each byte it receives to that file. However - more specifically with your code (if you're just trying to display it to the screen), is that you've programmed it to end as soon as it recieves the first byte: strstream=AcceptTCPStream(svrcom) If strstream Then Print ReadString$(strstream) WaitKey() End As soon as it gets a byte from the stream.. it ends. The server has to send EVERY byte in the file, one by one, from start to end, and the client has to recieve them in the same manner. The client needs to be passive, to constantly run and just accept whatever is sent to it. Otherwise it will never know when the end of the file is. Suggestion: read the tcp example programs and learn how they work first. :) I think maybe you've got completely the wrong idea of network coding.. +BlackD |
| ||
scuse me, that is the old code, the newest code write to a file, don't print in on the screen, but the problem is that it block as it write the first byte... |
| ||
And the new code is? ;) |
| ||
Scuse me, i resolve the problem and i'll need no help, thanks to you all. |
| ||
oh well, heres my code:Global stream Global streamx server=CreateTCPServer(4000) If server<>0 Then Print "Server started successfully." Else Print "Server failed to start." End End If Print "SERVER STARTED" a=0 While a=0 streamx=OpenTCPStream("localhost",4000) stream=AcceptTCPStream(server) Delay 500 If Not stream Print "NO STREAM 1" If streamx Then Print "Stream Connected sending file" a=1 Else Print "PAUSING" Delay 500 Print "reconnecting" EndIf Wend file=OpenFile("c:\agent.exe") fileout=WriteFile("c:\newagent.exe") a=0 Print "TRANSFER STARTED" While Not Eof(file) b=ReadByte(file) WriteByte(stream,b) WriteByte(fileout,b) Cls Text 10,10,a a=a+1 Wend CloseFile(file) CloseFile(fileout) CloseTCPStream(stream) CloseTCPStream(streamx) CloseTCPServer(server) Print "DONE DONE DONE" WaitKey() End WaitKey() |
| ||
wow there is alot of dead code in that last one. alot of globals that wasnt needed. it could be half of this, but thanks for the help. |
| ||
/me looks around for malicnite's coded example as an attempt to help rather than point out someone's mistake in a piece of code that probably took them 2 min to write up. hmmm, can't seem to see it. |
| ||
hey watch it buddy |
| ||
I believe the original problem was WriteByte() vs ReadString(). |