Jump to content

send file over tcp


pepe
 Share

Recommended Posts

HI...

I'm trying to make a connection to a client - server by tcp, which could send files larger than 1MB, but I don't know how...

please help me!!

I don't know whether to send it to me at a one time or do it in starges.

Sorry for my english

Edited by pepe
Link to comment
Share on other sites

yes, but the person would like to start write programs would need some tip.

I searched the forum and I can't see that there was something about tcp and files larger than 1mb

What's the problem with the files larger than 1mb ? you can send a whole data once, but It will block your script.

You need to use _WinAPI_ files functions, to split the data and read at X offset.

There is an example somewhere, just search for it.

Link to comment
Share on other sites

meybe could someone tell me that it's okay?

this is client

Func pobierz ()
$pobierz = FileOpenDialog ("Pobierz plik", @DesktopDir, "Wszystkie pliki (*.*)", 1)
  If @error Then
   MsgBox (0, "Informacja", "Nie wybrałes pliku")
  Else
   GUICtrlSetData ($input_pobierz, $pobierz)
  EndIf
$size = FileGetSize ($pobierz)
  If $size = 0 Then
   MsgBox(16 , "Błąd" , "Zły plik")
  EndIf
EndFunc
Func wyslij ()
$name = name ($input_pobierz)
TCPStartup ()
$socket = TCPConnect ("192.168.1.100", 1234)
  If $socket = -1 Then
   MsgBox (0, "Błąd", "Brak moliwosci nawiązania połączenia")
  EndIf
TCPSend($socket, $name & ":" & $size)
$return = False
$open = FileOpen ($input_pobierz)
$bytes = 0
While Not $return
  $data = FileRead ($open, $MAX_SIZE)
   If @error Then $return = True
   $bytes += TCPSend ($socket, $data)
   ToolTip(Round($bytes * 100 / $size, 2) & "%")
WEnd
FileClose ($open)
TCPShutdown ()
EndFunc
Func name ($input_pobierz)
$reg=StringRegExp($input_pobierz, "(.)+((.)+)?", 3)
If Not IsArray ($reg) Then Return $input_pobierz
If UBound ($reg) < 2 Then Exit
Return $reg[1]
EndFunc
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...