Posted: Tue Aug 06, 2002 6:53 am
Restored from previous forum. Originally posted by ricardo.
Im trying to send/receive some files using some threads.
After a small battle betewn mi PC and i, im making some advance, but im in one point that i can understand what is failing... its 3:30 a.m. maybe my brain dosent work anymore.
Please take a look and see if you can see what im doing wrong.
There are 2 procedures, one for every app (one for the client and one for the server) and both are working now on the same PC, that why both are calling to the same files.
This procedure runs everytime i click a button and its suppoused to send some file (a1.mp3, a2.mp3, a3.mp3, etc) to the server, i want to receive several files at the same time.
The index are the port of the server, cause every thread procedure on the server side has a different port (maybe there some oher way to do it)
Procedure EnviaFile(index.l)
Cont.l = Cont + 1 ; global
Buffer = AllocateMemory(Cont, FileSize("a" + str(cont) + .mp3"), 0)
OpenFile(Cont,"a"+ Str(Cont)+".mp3")
ReadData(Buffer,FileSize("a"+ Str(Cont)+".mp3"))
CloseFile(Cont)
ConnectionID = OpenNetworkConnection("127.0.0.1", (index))
If ConnectionID
SendNetworkData(ConnectionID, Buffer, FileSize("a"+ Str(Cont)+".mp3"))
CloseNetworkConnection(ConnectionID)
;FreeMemory(Cont)
EndIf
EndProcedure
;SERVER SIDE PROCEDURE
This one receives a1.mp3 and writes b1.mp3, etc.
Procedure RecibeFile(Index.l)
Result = CreateNetworkServer(Index)
Cont.l = cont + 1 ;global
Repeat
ServerEvent.l = NetworkServerEvent()
If ServerEvent
Select ServerEvent
Case 2
ClientID = NetworkClientID()
If FindString(IDClient,"*" + Str(cont) + "*",0) = 0; dirty
IDClient = IDClient + "*" + Str(cont) + "* "
Buffer = AllocateMemory(Cont, FileSize("a"+ Str(Cont)+".mp3"), 0)
ReceiveNetworkData(ClientID, Buffer, FileSize("a"+ Str(Cont)+".mp3"))
OpenFile(Cont,"b"+ Str(Cont)+".mp3")
WriteData(Buffer,FileSize("a"+ Str(Cont)+".mp3"))
CloseFile(Cont)
CloseNetworkConnection(Result)
;FreeMemory(Cont)
Conectado.l = 1
EndIf
Case 4
CloseNetworkConnection(Result)
Conectado.l = 1
EndSelect
EndIf
Until Conectado = 1
EndIf
EndProcedure
The result i that i can send/receive apparentely 3 or more files, but writes always the same one.
I make the DIRTY trick because the ServerEvent is received on every thread no matter if its originated on the server connected to another thread and since im using only one client the ClientID is the same too, then i make this dirty trik to know if the event comes from one thread different from this one.
When the server receives some text message, it run s the procedure with a new thread and replay to the client the number of the port recently opened and the waits until getting the file.
And seems to work, create a file with the correct size, but the content of the file is wrong.
The idea is to receive at the same time several files from one or more clients to the same server... but it dosent works ¿any help?
Im trying to send/receive some files using some threads.
After a small battle betewn mi PC and i, im making some advance, but im in one point that i can understand what is failing... its 3:30 a.m. maybe my brain dosent work anymore.
Please take a look and see if you can see what im doing wrong.
There are 2 procedures, one for every app (one for the client and one for the server) and both are working now on the same PC, that why both are calling to the same files.
This procedure runs everytime i click a button and its suppoused to send some file (a1.mp3, a2.mp3, a3.mp3, etc) to the server, i want to receive several files at the same time.
The index are the port of the server, cause every thread procedure on the server side has a different port (maybe there some oher way to do it)
Procedure EnviaFile(index.l)
Cont.l = Cont + 1 ; global
Buffer = AllocateMemory(Cont, FileSize("a" + str(cont) + .mp3"), 0)
OpenFile(Cont,"a"+ Str(Cont)+".mp3")
ReadData(Buffer,FileSize("a"+ Str(Cont)+".mp3"))
CloseFile(Cont)
ConnectionID = OpenNetworkConnection("127.0.0.1", (index))
If ConnectionID
SendNetworkData(ConnectionID, Buffer, FileSize("a"+ Str(Cont)+".mp3"))
CloseNetworkConnection(ConnectionID)
;FreeMemory(Cont)
EndIf
EndProcedure
;SERVER SIDE PROCEDURE
This one receives a1.mp3 and writes b1.mp3, etc.
Procedure RecibeFile(Index.l)
Result = CreateNetworkServer(Index)
Cont.l = cont + 1 ;global
Repeat
ServerEvent.l = NetworkServerEvent()
If ServerEvent
Select ServerEvent
Case 2
ClientID = NetworkClientID()
If FindString(IDClient,"*" + Str(cont) + "*",0) = 0; dirty
IDClient = IDClient + "*" + Str(cont) + "* "
Buffer = AllocateMemory(Cont, FileSize("a"+ Str(Cont)+".mp3"), 0)
ReceiveNetworkData(ClientID, Buffer, FileSize("a"+ Str(Cont)+".mp3"))
OpenFile(Cont,"b"+ Str(Cont)+".mp3")
WriteData(Buffer,FileSize("a"+ Str(Cont)+".mp3"))
CloseFile(Cont)
CloseNetworkConnection(Result)
;FreeMemory(Cont)
Conectado.l = 1
EndIf
Case 4
CloseNetworkConnection(Result)
Conectado.l = 1
EndSelect
EndIf
Until Conectado = 1
EndIf
EndProcedure
The result i that i can send/receive apparentely 3 or more files, but writes always the same one.
I make the DIRTY trick because the ServerEvent is received on every thread no matter if its originated on the server connected to another thread and since im using only one client the ClientID is the same too, then i make this dirty trik to know if the event comes from one thread different from this one.
When the server receives some text message, it run s the procedure with a new thread and replay to the client the number of the port recently opened and the waits until getting the file.
And seems to work, create a file with the correct size, but the content of the file is wrong.
The idea is to receive at the same time several files from one or more clients to the same server... but it dosent works ¿any help?