Using Sockets and transfer more than one line

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
ace16vitamine
Posts: 130
Joined: Fri Apr 13, 2018 1:53 pm

Using Sockets and transfer more than one line

Post by ace16vitamine » Mon Jun 18, 2018 2:08 pm

Dear all,

i have created two simple applications, 1st is the Server application, 2nd is the Client Application.

Now I try to transfer the following string from the client to the server, but on the Server App I only receive the first Line. Why? The string comes from test.txt with the content:

Line 1 CR
Line2 CR
Line3


Server:

Code: Select all

on mouseUp
   accept connections on port 8080 with message "is_Connected"
   end mouseUp

on is_Connected theIP
   read from socket theIP until return with message "newMessage"
  end someoneConnected

on newMessage theIp theMessage
####   --put theIP & ":" && theMessage & return after field "text"
   
####   --read from socket theIP until return with message "newMessage"
   answer theMessage 
#### Check the transferred string
   
end newMessage

Client:

Code: Select all

   
   ## open the file text.txt with the content into theFile3
   local tPath
   put the effective filename of this stack into tPathmailconfig
   set the itemDelimiter to slash
   delete last item of tPathmailconfig
   put tPathmailconfig & "/test.txt" into theFile3
   put url("file:" & thefile3) into socketfile
   answer socketfile
   ## File read done, seems complete
   
 
 open socket to "localhost:8080"
   if the Result <> "" then
      put "result:" && the result
   end if
   
   write socketfile to socket "localhost:8080"
   close socket "localhost:8080"
   
   
   
end mouseUp

tomBTG
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 73
Joined: Fri Nov 25, 2011 6:42 pm
Location: Kansas City

Re: Using Sockets and transfer more than one line

Post by tomBTG » Tue Jun 19, 2018 3:39 pm

Hi,

Instead of "read from socket theIP until return" use some other character to mark the end of your message and read until that character appears.

Msg of Line 1 CR
LINE 2 CR
LINE 3*

And fetch that with "read from socket theIP until * with "newMessage"

Better?
Tom B.

ace16vitamine
Posts: 130
Joined: Fri Apr 13, 2018 1:53 pm

Re: Using Sockets and transfer more than one line

Post by ace16vitamine » Tue Jun 19, 2018 4:28 pm

Thats it, thank you!

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”