JPG File Transfer

Deploying to Windows? Utilizing VB Script execution? This is the place to ask Windows-specific questions.

Moderators: heatherlaine, Klaus, FourthWorld, robinmiller, kevinmiller

Post Reply
Googie85
Posts: 77
Joined: Tue Aug 05, 2014 10:07 am

JPG File Transfer

Post by Googie85 » Mon Jan 15, 2018 7:11 am

I have a client/server application that I have been having some problems with. The JPG keeps on getting corrupted and will not work. Here is my code:-

Server.

Code: Select all

global flower

on openStack
   accept connections on port 12345 with message "connectionMade"
   put "" into field "Edit"
end openStack

on connectionMade pIPAddress
   put pIPAddress&CR after field "Edit"
   read from socket pIPAddress until return with message "newMessage"
 end connectionMade
 
 on newMessage theIP theMessage
    put theMessage after flower

    if flower contains "EXPLORE" then
       replace "EXPLORE" with "" in flower
  put base64Decode(flower) into URL "file:tester.jpg"
           put "" into flower
    end if
           read from socket theIP until return with message "newMessage"
 end newMessage
Client.

Code: Select all

local lSock = "192.168.15.189:12345"

on openStack
  newConnection
end openStack

on newConnection
  if lSock is not among the lines of the openSockets then
    open socket lSock with message "CONNECTED"
    send "newConnection" to me in 15 seconds
  end if
end newConnection

on CONNECTED theIp
   read from socket theIp until return with message "newMessage"
end CONNECTED

on newMessage theIp theMessage
   
   if theMessage = "Download" & return then
      answer "Download"
      put the base64encode of URL "binfile:c:\windows\temp\ScreenShot.jpg" into blah
            put "EXPLORE" after blah
      write blah to socket "192.168.15.189:12345"
      read from socket theIp until return with message "newMessage"
   end if
end newMessage
All help would be very greatful!!!

Many Thanks,

Googie.

Googie85
Posts: 77
Joined: Tue Aug 05, 2014 10:07 am

Re: JPG File Transfer

Post by Googie85 » Wed Jan 17, 2018 1:30 am

Im still having troubles... here is my complete code:

Client:

Code: Select all

local lSock = "192.168.15.189:12345"

on openStack
  newConnection
end openStack

on newConnection
  if lSock is not among the lines of the openSockets then
    open socket lSock with message "CONNECTED"
    send "newConnection" to me in 15 seconds
  end if
end newConnection

on CONNECTED theIpZ
   read from socket theIpZ until return with message "newMessage"

end CONNECTED

on newMessage theIp theMessage
   
   if theMessage = "Download" & return then
      answer "Download"
      put URL "binfile:c:\windows\temp\Tester.jpg" into Temp1
      put the base64encode of Temp1 into blah1
      put "PUMP" after blah1
      write blah1 to socket theIp
      
      put "" into blah1
      
      read from socket theIp until return with message "newMessage"
      answer theIp
   end if
end newMessage

Server:-

Code: Select all

on openStack
   accept connections on port 12345 with message "connectionMade"
   put "" into field "Edit"
end openStack

on connectionMade pIPAddress
   put pIPAddress&CR after field "Edit"
   read from socket pIPAddress until return with message "newMessage"
   
 end connectionMade

 on newMessage theIP theMessage
      put theMessage after flower
    if flower contains "PUMP" then
       replace "PUMP" with "" in flower
           put base64Decode(flower) into URL "binfile:tester.jpg" 
  answer "PUMP"
  put "" into flower
  read from socket theIP until return with message "newMessage"
  break
end if
           read from socket theIP until return with message "newMessage"
 end newMessage

on Download
      put the selectedtext of field "Edit" into Blah
   answer Blah
   	write "Download" & return to socket Blah
       read from socket theIP until return with message "newMessage"
end Download
Please Help!!!

Googie.

MaxV
Posts: 1467
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: JPG File Transfer

Post by MaxV » Fri Jan 19, 2018 1:42 am

Code: Select all

... until return ...
???
Are you sure that you don't have the return char in jpg images?
I'd use something a little more unique like

Code: Select all

until "EOF"
and I'd add "EOF" at the end of file

However I wrote guide on sockets here: https://livecodeitalia.blogspot.it/2017/08/sockets.html
Livecode Wiki: http://livecode.wikia.com
My blog: http://livecodeitalia.blogspot.it
To post code use this: http://tinyurl.com/ogp6d5w

Post Reply

Return to “Windows”