Sockets = fail

Bringing the internet highway into your project? Building FTP, HTTP, email, chat or other client solutions?

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
BobM
Posts: 7
Joined: Wed Apr 19, 2017 7:30 pm

Sockets = fail

Post by BobM » Wed Apr 19, 2017 8:34 pm

I am attempting to use sockets using the sample client and server stacks here: [forum won't let me post links!]

Stacks and code can be seen [forum won't let me post links!]

I am having exactly zero success, and because it seems that almost nothing happens on the server side I can't even begin to debug things.

Code: Select all

accept connections on port 9001 with message "someoneConnected"
As near as I can tell the message someoneConnected never gets sent.

Modifying the code a bit

Code: Select all

accept connections on port 9001 with message "someoneConnected"
put the opensockets
returns 9001 in the message box.

on the client side put the opensockets returns the full IP:port of the expected socket.

hardware is two laptops both running linux mint hanging on the same switch.
Firewalls are fully permissive, and each can connect to the other with Nemo.

The sample stacks appear to me to be fully consistent with the official lesson at [forum won't let me post links!]

I welcome any constructive suggestions about what to look at to help troubleshoot.

Klaus
Posts: 9528
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Sockets = fail

Post by Klaus » Wed Apr 19, 2017 8:49 pm

Hi Bob,

1. welcome to the forum! :D

2. There is really no need for creating a report for your simple question! 8)
Due to high spam traffic, you need to have at least 10 postings before you can post links and create attachments etc.

Hint:
Add a SPACE or something so the forum software cannot recognize your URL as such!

3. What version of LC are you using?

4. What did you script on the client side?


Best

Klaus

BobM
Posts: 7
Joined: Wed Apr 19, 2017 7:30 pm

Re: Sockets = fail

Post by BobM » Wed Apr 19, 2017 9:07 pm

Attempted various mutations of link URLs without success.

on the client side:

Code: Select all

open socket to servAddr
where servAddr is a.b.c.d:9001

and a.b.c.d is the hostNameToAddress of the hostName from the server

LC v 8.1.3 community edition

Klaus
Posts: 9528
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Sockets = fail

Post by Klaus » Wed Apr 19, 2017 9:10 pm

I'm not an expert at socket communication stuff, but did you actually write something to the socket on the client side?
I think only that will trigger the message "someoneConnected".

AxWald
Posts: 284
Joined: Thu Mar 06, 2014 2:57 pm

Re: Sockets = fail

Post by AxWald » Thu Apr 20, 2017 7:49 am

Hi,

from a running socket solution:

Server:

Code: Select all

accept connections on port gPort with message "ServerClientConnected"
...
on ServerClientConnected pSocket
      put pSocket & return after gSockets     
      put "You're welcome!" into MyMsg
      write "CON OK, " & length(MyMsg)& return & MyMsg to socket pSocket
      read from socket pSocket until return with message "ServerMessageReceived"
...
Client:

Code: Select all

open socket to pServer & ":" & kPort with message "ClientConnected"
...
on ClientConnected pSocket
    put pSocket into sSocket
    read from socket sSocket with message "ClientMessageReceived"
...
on ClientSend
   if sSocket is not empty then
      Put the theCMD of this stack & "," & length(fld MyText) & return & fld MyText into myVar
      write MyVar to socket sSocket        
...
Runs flawlessly on Win XP and newer, LC in various v6 flavors.

Have fun!
Livecode programming until the cat hits the fan ...

BobM
Posts: 7
Joined: Wed Apr 19, 2017 7:30 pm

Re: Sockets = fail

Post by BobM » Thu Apr 20, 2017 8:29 pm

Thank you AxWald

Based on your example, I have:

Code: Select all

Server:

on mouseUp #Button StartServer
  close socket 9000
  put empty into field "text"
  accept connections on port 9000 with message "someoneConnected"
  put the opensockets after field "text"
end mouseUp


on openCard
put the hostNameToAddress of the hostName into theAddr
set the itemDelimiter to return
put (item 1 of theAddr) into the field "serverAddr"
end openCard

on someoneConnected theirSocket
put theirSocket intofield"ClientID"
Write "Server got your message" to socket theirSocket
read from socket theirSocket until return with message "newMessage"
end someoneConnected

on newMessage theirSocket theMessage
put theirSocket & ":" && theMessage & returnafterfield"text"
read from socket theirSocket until return with message "newMessage"
end newMessage
and

Code: Select all

Client:
on mouseup #Button Connect
open socket to field "serverAddr" with message "ClientConnected"
end mouseUp

on ClientConnected pSocket
   put pSocket into field "ConfirmServer"
   read from socket pSocket with message "ClientMessageReceived"
end ClientConnected

on ClientMessageReceived
   answer "Something was received"
end ClientMessageReceived

on mouseUp #Button Send
    write field "message" & return to socket field "ServerAddr"
end mouseUp
This does not work.

Here is what happens.

On the Server.
on mouseUp #Button StartServer
close socket 9000
put empty into field "text"
accept connections on port 9000 with message "someoneConnected" ---> the message someoneConnect is not sent
put the opensockets after field "text" -->the field "text" displays 9000
end mouseUp

On the Client.
on ClientConnected pSocket
put pSocket into field "ConfirmServer" --->the full socket name IP:Port is place into the field
read from socket pSocket with message "ClientMessageReceived"---> message never sent
end ClientConnected

Interestingly (to me at least) is that the message "ClientConnected" is sent even if the client computer is not connected to the network.

I don't know how to troubleshoot from here because nothing else happens. Suggestions welcome.

BobM
Posts: 7
Joined: Wed Apr 19, 2017 7:30 pm

Re: Sockets = fail

Post by BobM » Fri Apr 21, 2017 2:56 pm

Looking at this in more detail:
LiveCode Language Dictionary
callbackMessage The name of a message to be sent when the connection is made.
Yet on my client laptop this line completes and sends the "ClientConnected" message

open socket to field "serverAddr" with message "ClientConnected"

Even when the client laptop has no connections to anything. WiFi off. Network cable unplugged.

It is clearly impossible for a connection to be made from a laptop that has no connectivity.

Why is the callbackMessage sent?

BobM
Posts: 7
Joined: Wed Apr 19, 2017 7:30 pm

Re: Sockets = fail

Post by BobM » Fri Apr 21, 2017 4:21 pm

Solved:

the hostNameToAddress of the hostName

is expected to return the IPv4 address of the computer.

On Linux Mint it does NOT. [confirmed bug 5909 {unresolved in 9 years! :oops: }]

Socket communication working correctly when correct IPv4 address is used with open socket to.

Post Reply

Return to “Internet”