Making an ultra-simple Livecode server and client

Want to talk about something that isn't covered by another category?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Livecoder
Posts: 6
Joined: Tue Feb 18, 2014 4:23 pm

Making an ultra-simple Livecode server and client

Post by Livecoder » Tue Feb 18, 2014 4:48 pm

Hi everyone, i'm new to this forum but i'm stuck trying to build a simple server. I'm trying to be able to have a client receiving a variable from the server when a button is clicked. But I don't know where to start. If anyone could help that would be brilliant.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10045
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Making an ultra-simple Livecode server and client

Post by FourthWorld » Tue Feb 18, 2014 8:14 pm

See the Chat Example included in the LiveCode install - in the IDE, click "Resources" in the toolbar, and you'll find the Internet Chat example near the bottom of the list in that window.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: Making an ultra-simple Livecode server and client

Post by bangkok » Tue Feb 18, 2014 8:15 pm


Livecoder
Posts: 6
Joined: Tue Feb 18, 2014 4:23 pm

Re: Making an ultra-simple Livecode server and client

Post by Livecoder » Thu Feb 20, 2014 5:41 pm

Thank you very much for your replies, I have come up with some code, but it doesn't seem to work could someone possibly have a look at it and tell me what I am doing wrong.

This is the button that connects to the server:

Code: Select all

on mouseUp
   open socket "localhost" & ":*" with message "chatConnected"

 
end mouseUp

on chatReceived s,data
   put data into field "got"
end chatReceived

on chatConnected s 
      read from socket s with message chatReceived
end chatConnected

This is the button that starts the server:

Code: Select all


on mouseUp
   local connected
   accept connections on port * with message chatConnected
   put s into connected
end mouseUp

on chatConnected s
   write "hello" to socket connected
end chatConnected
I am simply trying to get the field "got" to display "hello".

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10045
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Making an ultra-simple Livecode server and client

Post by FourthWorld » Thu Feb 20, 2014 5:43 pm

I think you'll need to specify a port number rather than attempt all with "*".
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Klaus
Posts: 14190
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Making an ultra-simple Livecode server and client

Post by Klaus » Thu Feb 20, 2014 5:47 pm

FourthWorld wrote:I think you'll need to specify a port number rather than attempt all with "*".
Yep, or just omit it completely if you can live with port 80 :D

From the docs about "socket":
...
Parameters:
host - The IP address or domain name of the host you want to connect to.
port - The port number you want to connect to. If you don't specify a port, port 80 is used.
(On most systems, port 80 is used for HTTP connections.).
...

Livecoder
Posts: 6
Joined: Tue Feb 18, 2014 4:23 pm

Re: Making an ultra-simple Livecode server and client

Post by Livecoder » Thu Feb 20, 2014 5:50 pm

FourthWorld wrote:I think you'll need to specify a port number rather than attempt all with "*".
I replaced the port I am using with a "*" for security purposes for when I was positing it on this forum. I do not know if it is safe to post which ports I am using online. Is it?

Klaus
Posts: 14190
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Making an ultra-simple Livecode server and client

Post by Klaus » Thu Feb 20, 2014 6:11 pm

Oh, sorry, we saw this as a "wildcard" :D

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10045
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Making an ultra-simple Livecode server and client

Post by FourthWorld » Thu Feb 20, 2014 6:34 pm

Are you testing on a local network, or is the server behind a different router? If the latter you'll need to set up port forwarding on the router to allow connections.

If you've already done that you may need to check the value of "the result" after the connection attempt to see if you can get more info about what's going on.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Livecoder
Posts: 6
Joined: Tue Feb 18, 2014 4:23 pm

Re: Making an ultra-simple Livecode server and client

Post by Livecoder » Thu Feb 20, 2014 7:18 pm

Right, I think I found my problem, it comes from the client end,

Code: Select all

   read from socket s with message chatReceived
   answer "read it"

I do not get the pop-up.
What am i doing wrong here?
:?:

By the way, I am using both programs on the same computer

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10045
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Making an ultra-simple Livecode server and client

Post by FourthWorld » Thu Feb 20, 2014 7:28 pm

Is the port in use by another program?

You may need to check the value of "the result" after the connection attempt to see if you can get more info about what's going on.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Livecoder
Posts: 6
Joined: Tue Feb 18, 2014 4:23 pm

Re: Making an ultra-simple Livecode server and client

Post by Livecoder » Thu Feb 20, 2014 7:31 pm

I think I solved that, the problem actually lies in the server end,

Code: Select all

   write "hello" to socket connected
   answer "Sent"

You do not get the sent pop-up, that explains why the client could not read it, it was never sent!
So my real question should be what am I doing wrong on the server end?

I do not know if the port is in use, I tried another one and still no luck

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10045
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Making an ultra-simple Livecode server and client

Post by FourthWorld » Thu Feb 20, 2014 9:09 pm

Sending data from the server is the third thing that happens. First the server sets itself up on the port, then the client connects to it. It may be worthwhile checking the earlier two events.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

sefrojones
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 447
Joined: Mon Jan 23, 2012 12:46 pm

Re: Making an ultra-simple Livecode server and client

Post by sefrojones » Tue Feb 25, 2014 3:31 am

Maybe this example will give you some insight:

https://sites.google.com/a/pgcps.org/li ... uter-games

Good Luck! :wink:

Post Reply