Page 1 of 1

Using Sockets and transfer more than one line

Posted: Mon Jun 18, 2018 2:08 pm
by ace16vitamine
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

Re: Using Sockets and transfer more than one line

Posted: Tue Jun 19, 2018 3:39 pm
by tomBTG
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.

Re: Using Sockets and transfer more than one line

Posted: Tue Jun 19, 2018 4:28 pm
by ace16vitamine
Thats it, thank you!