How to write a VERY simple server?

Alex Tweedly alex at tweedly.net
Wed Aug 24 19:27:09 EDT 2005


Gajo Csaba wrote:

>Hi,
>
>I started learning Revolution today, though I have been programming in 
>other languages such as Java for many years before. What I'd like to do 
>is create a simple chat program. I managed to write the client part and 
>send a message to a Java server application, but I just cannot build a 
>server. All the server has to do is listen to connections on port 5001, 
>accept a connection, read from the socket until linefeed and then 
>terminate the connection. After that it should put the text in some field 
>for display.
>
>I did search through your list and saw a few examples, but they didn't 
>work. There was also a link to a ZIP-ed chat program source which I 
>downloaded, but the file was corrupted.
>  
>
There are a number of examples out there - and they do work. So I'm 
slightly concerned that you found some which don't - it would be helpful 
if you could let us know which ones you tried without success. Hopefully 
that would lead to either answers to make them work for you, or changes 
to make them work for the next person who tries them.

You can find my version in RevOnline, under username "alextweedly" - the 
TCP version is called TCPApp1 and TCPApp2. TCPApp1 is basically a 
server, TCPApp2 basically a client - though they have been extended to 
allow asynchronous communication initiated by either side once the 
connection is open.

>So could someone please just type down the source of a simple server 
>script? On the Runtime's site they say you can write a client/server with 
>just a few lines, so I'm sure it's very simple, but I cannot figure it out.
>  
>
I'd encourage you to try the samples above, or to work with the ones you 
found earlier.

But - simple code -  the script for some object to do this could be as 
simple as


on mouseUp
  accept connections on port 5001 with message "gotConn"
end mouseUp

on gotConn pSocket
  read from socket pSocket until CR
  put it into field "myData"
  close socket pSocket
end gotConn




-- 
Alex Tweedly       http://www.tweedly.net



-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.338 / Virus Database: 267.10.15/80 - Release Date: 23/08/2005




More information about the use-livecode mailing list