How to write a VERY simple server?

Gajo Csaba gcsaba2 at freemail.hu
Wed Aug 24 20:10:05 EDT 2005



Mark Wieder <mwieder at ahsoftware.net> wrote:

>
> Try something like this...
> 

Wow that was a quick reply. OK, it still doesn't work for some reason. 
My only clue now is that I've made a stupid mistake somewhere.

This is the code when I click on the "Send message" from the client's 
side.

on mouseUp
  put "localhost:5007" into sock
  open socket sock with message "hello"
  write "Apples are red" & linefeed to socket sock
  write "Quit" & linefeed to socket sock
  close socket sock
end mouseUp

So basically I send "Apples are red" to the server and it should write 
this into a text field. After that I write him "Quit" and the server should 
stop receiving.

This is what happens when I click on the "Accept connections" button 
on the server's side. It's basically your code, just one line was changed.

-- PortOpened is called when someone connects
on PortOpened theSender, sentMessage
  local theMessage
 
  -- get a command from the client
  put empty into theMessage
  repeat while "Quit" is not in theMessage
    read from socket theSender until linefeed  -- read until linefeed
    put it into theMessage
    if theMessage is not empty then
      switch word 1 of theMessage
        -- do something with the message here
        put theMessage into field "serverMemo"
      end switch
    end if
  end repeat
end PortOpened

-- this is the button's code

on mouseUp
  accept connections on port 5007 with message "PortOpened"
end mouseUp

So what am I doing wrong? The client's code works as my Java server 
accepted it...


******************

Alex's code doesn't work either :(

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

*****************

Maybe I'm doing something very stupid here? Maybe I should separate 
the client and the server card? Right now both the client and server 
buttons are on the same card, but I save them as a Standalone 
application and start two instances, with one of them working as a 
server and another as a client.
The client should work, as I already said. There's another indication that 
the server code doesn't do anything: I have a firewall software which 
always reports me if some application is trying to become a server. But 
when I click on the server's "Accept" button the firewall doesn't report 
anything!
I tried turning the firewall off but this didn't change anything.

*****************

Alex now I will go and search for your application. Let's hope that it 
works ;)

*******************

The example that I've found and it didn't work is here: 
http://lists.runrev.com/pipermail/use-revolution/2004-March/033397.
html
I downloaded the .gz file but both WinZip and WinRar said the file's 
corrupted.

This example didn't work either:
http://lists.runrev.com/pipermail/use-revolution/2004-March/033388.
html

The code also has some minor errors, such as closing the "on" 
statement with another "on" instead of an "end".


Thank you if you've read my e-mail all the way to the end :)

Csaba

_______________________________________________________________________
[freemail] extra 1GB-os postafiókkal, Önnek már van? http://freemail.hu





More information about the use-livecode mailing list