Forgive the lack of brevity here… but the goal is to exchange data (or even synchronize it) between an OS X app and an iOS app over the network.
Not having any real experience with sockets, I broke down the Chat sample to separate server and client apps, which work between two desktops. I can transfer files and data snippets from one Mac to another over a wifi network, and it all works rather well.
Code: Select all
--HERE IS THE TEST CODE FOR THE SERVER
global clientSocket
on mouseUp
  -- provide visual feedback the server has been started
  disable me
  -- make it possible to stop the server
  enable button "Stop server"
  accept connections on port 1987 with message clientConnected
end mouseUp
on clientConnected s
   put s &CR before fld 1
   -- read in one line of data from the socket identified in the "s" variable
   read from socket s for 1 line
   -- remove any trailing return character
   put line 1 of it into tChatMessage
   put s into clientSocket
   put tChatMessage && "connected" & return after field "serverstatus"
   read from socket s until "scottyb" with message dataReceivedfromClient
end clientConnected
on dataReceivedfromClient s,data
   get the number of chars of data
   put it-6 into tstart
   delete char tstart to it of data
   --put "Client Data received"
   set the itemdel to tab
   if item 1 of data is "file" then
      put "received " & item 1 of data into whatwegot
      put whatwegot && "from" && s & CR before field "serverstatus"
      delete item 1 of data
      writethefile data
   else
      put  data & return before field "serverstatus"
   end if
   read from socket s until "RUSStyb" with message dataReceivedfromClient
   write "Data Received from"&&S&&"at"&&the time to socket clientSocket
end dataReceivedfromClient
on socketClosed s
   put s && "disconnected" & return before field "serverstatus"
end socketClosed
on writethefile data
   set the itemdel to slash
   put item 1 to -2 of the filename of this stack into thefolder
   put thefolder &"/myPict.jpeg" into thefile
   open file thefile for binary write
   write data to file thefile
   close file thefile
end writethefile
Code: Select all
--HERE IS THE CLIENT TEST CODE
local lCommSocket
on ClientConnect
   open socket field "host" & ":1987" with message "ClientConnected"
   set the label of button "connect" to "Disconnect"
end ClientConnect
on ClientDisconnect
   close socket lCommSocket
   set the label of button "connect" to "Connect"
end ClientDisconnect
on closeStack
  ClientDisconnect
end closeStack
on ClientConnected s
   set the label of button "connect" to "Disconnect"
   put s into lCommSocket
   write field "username" & return to socket lCommSocket
   read from socket s with message dataRecievedFromClient
end ClientConnected
on dataRecievedFromClient s,data
   put data & return before field "responses"
   -- specify that this message is to be sent again when more data is received
   read from socket s with message dataRecievedFromClient
end dataRecievedFromClient
on socketerror s,data
  set the label of button "connect" to "Connect"
  answer data
end socketerror
on sendData data
   set the itemdel to tab
   if item 1 of data is "file" then
      write data&"RUSSyb" to socket lCommSocket
   else write field "username" & ":" & data &"RUSSyb" to socket lCommSocket
end sendData
on ClientDisconnect
   close socket lCommSocket
   set the label of button "connect" to "Connect"
end ClientDisconnect
Thanks!
Code: Select all
--iOS CLIENT TEST CODE
local lCommSocket 
on ClientConnect
   rreSocketOpen field "host" & ":1987", "ClientConnected"
   set the label of button "connect" to "Disconnect"
end ClientConnect
on ClientDisconnect
   rreSocketClose lCommSocket
   --  close socket lCommSocket
   set the label of button "connect" to "Connect"
end ClientDisconnect
on closeStack
  ClientDisconnect
end closeStack
on ClientConnected s
   set the label of button "connect" to "Disconnect"
   put s into lCommSocket
   rreSocketWrite lCommSocket, field "username" & return
   --   write field "username" & return to socket lCommSocket
   rreSocketRead s, , "dataRecievedFromClient"
   --   read from socket s with message dataRecievedFromClient
end ClientConnected
on dataRecievedFromClient s,data
   put data & return before field "responses"
   -- specify that this message is to be sent again when more data is received
   rreSocketRead s, , "dataRecievedFromClient"
   --read from socket s with message dataRecievedFromClient
end dataRecievedFromClient
on socketerror s,data
  set the label of button "connect" to "Connect"
  answer data
end socketerror
on sendData data
   rreSocketWrite lCommSocket, field "username" & ":" & data &"RUSSyb"
   --set the itemdel to tab
   --   if item 1 of data is "file" then
   --      write data&"RUSSyb" to socket lCommSocket
   --   else write field "username" & ":" & data &"RUSSyb" to socket lCommSocket
end sendData

 I can assure you they match on this end.
  I can assure you they match on this end.


