Repeat TCP information Sending

BlitzPlus Forums/BlitzPlus Beginners Area/Repeat TCP information Sending

I recently began trying to create a program that could access my computer from any random other computer over the internet. However, whenever i opened up a TCP stream, it seems to only allow me a single "WriteLine FILE,str$" command before the stream terminates. So to bypass this i must close the old stream and open a new one. How do you bypass this inconvinience? It wouldn't be that bad if it didn't play havock with dos's "netstat" command, which i assume is a bad thing. Anyway here's the code below if it helps identify the problem.

-------------------------------------Server Code-------------------------------
Global fileout
Remote=CreateTCPServer(1026)

If Remote<>0 Then
Print "Server started successfully."
Else
Print "Server failed to initialize."
Delay(2000)
End
End If

Print "awaiting connection..."

While stream = 0
stream=AcceptTCPStream(Remote)
Wend

Compname$ = ReadString$(stream)

Print "Connected To Computer " + Compname + " at "
Print TCPStreamIP(stream)
fileout=WriteFile("C:\" + Compname + ".txt")

While Not KeyHit(1)
Stream=AcceptTCPStream(remote)
If Stream Then
Print ReadString$(stream)
WriteLine(fileout,ReadString$(stream))
End If
Wend

------------------------------------Remote Code---------------------------------
Global xdir2$ = ""
Global xdir
Global xname$ = "C:\"
Print "working..."
TCPHome=OpenTCPStream("192.168.1.102",1026)
WriteString TCPHome,GetEnv("computername")
;CloseTCPStream tcphome
Delay(1000)
If TCPHome <> 0
Delay(100)
xdir = ReadDir(xname$)
Repeat
FILE=OpenTCPStream("192.168.1.102",1026)
xdir2$=NextFile$(xdir)
If xdir2 = "" Then Exit
If FileType(xname$+"\"+xdir2) = 2
WriteString FILE,("Folder: " + xname$ + xdir2)
Else
WriteString FILE,("File: " + xname$ + xdir2)
End If
Delay(100)
CloseTCPStream FILE
Forever
EndING=OpenTCPStream("192.168.1.102",1026)
WriteString EndING,"Program Successfully Executed. Exiting Now"
End If

CloseTCPStream tcphome
CloseTCPStream ending

Print "done!"

I use port 1026 to bypass the WinXP firewall.

note how i close the TCP stream FILE with every loop... thats what my problem is.

Nevermind i got it now, its not the best fix but its a pretty good patch. Thanks anyway

Well, you should state here what you did, so others will know how to correct similar problems.

ok fine I can do that... All I did was have the program send everything I wanted it to using the writeline command, then I used an EOF, readline command on the recieving end. anyways heres the code AND it's in the format that wol pointed out to me, although I still can't get it to work.
 Print "working..."
Global xdir2$ = ""
Global xdir
Global xname$ = "C:"

While Not tcphome
	TCPHome=OpenTCPStream("XXX.XXX.XXX.XXX",8080)
Wend

WriteString TCPHome,GetEnv("computername")
CloseTCPStream tcphome
Delay(1000)
If TCPHome <> 0
	Delay(100)
	xdir = ReadDir(xname$)
	While Not file
		FILE=OpenTCPStream("XXX.XXX.XXX.XXX",8080)
	Wend
	Repeat
		xdir2$=NextFile$(xdir)
		If xdir2 = "" Then Exit
		If FileType(xname$+""+xdir2) = 2
			WriteLine FILE,("Folder: " + xname$ + xdir2)
		Else
			WriteLine FILE,("File: " + xname$ + xdir2)
		End If
		Delay(10)
	Forever
	WriteLine file,"Program Successfully Executed.  Exiting Now"
	CloseTCPStream file
End If

Print "done!" 


and
Global fileout
Remote=CreateTCPServer(8080)

If Remote<>0 Then 
	Print "Server started successfully."
Else
	Print "Server failed to initialize."
	Delay(2000)
	End
End If 

Print "awaiting connection..."

While stream = 0
	stream=AcceptTCPStream(Remote)
Wend

Compname$ = ReadString$(stream)

Print "Connected To Computer " + Compname + " at "
Print DottedIP$(TCPStreamIP(stream))
If FileType("C:" + Compname + ".txt") Then DeleteFile("C:" + Compname + ".txt")
fileout=WriteFile("C:" + Compname + ".txt")

Delay(10000)

stream = AcceptTCPStream(remote)

While Not Eof(stream)
	Linein$ = ReadLine(stream)
	Print linein
	WriteLine(fileout,linein)
Wend

While Not KeyDown(1)
Wend