Socket Server on an Android Device

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
ChrisP
Posts: 4
Joined: Fri Apr 17, 2020 4:54 pm

Socket Server on an Android Device

Post by ChrisP » Sun Apr 19, 2020 4:35 pm

My purpose is to run a Socket Server on an Android device.

Mine is a Samsung Galaxy Note NT-5110, but I tested the following code on other Tablets with the same Result.

When I run the handler on PC, it works fine.
But when I try to accept a Connection on Android, I always receive the same Error : "Can't reuse port" !

I scanned the whole range of Ports (1 - 65 535) and the Device answer is always the same The Result ="Can't reuse port" .
I indeed checked the INERNET permission in the Android Application Permissions.

Where is my Error ?

Code: Select all

 local  tServerPort, tResult, tPort
   
   put 23100 into tServerPort  // or whatever port in 1-65535 range
   accept connections on port tServerPort with message "newClient"  
   put the result into tResult
   put it into tport
   put "SERVER Accepting Connection on Port    : " & tServerPort into fld "serverStatus"
   if tResult is empty then
      put return &  "Open Port : "& tServerPort after fld "serverStatus"
   else
      // HERE is the fatal result on Tablet : can't reuse port
      put return & "Error : "  &  tResult after fld "serverStatus"
   end if

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Socket Server on an Android Device

Post by FourthWorld » Sun Apr 19, 2020 5:44 pm

P2P is problematic in many environments, esp. business where firewalls are strict.

Most such apps have either migrated to client-server, or at least use client-server as a fallback when the app encounters the inevitable moment of a properly-configured firewall.

Can you tell us a bit more about your goal with this app, and why P2P appears an attractive approach for it?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

ChrisP
Posts: 4
Joined: Fri Apr 17, 2020 4:54 pm

Re: Socket Server on an Android Device

Post by ChrisP » Sun Apr 19, 2020 6:35 pm

Thanks FourthWorld for taking care of my issue.

I work on a companion App for a complex wargame (Napoleon at Bay _ OSG).


My aim is to have a player aid on 2 Android devices, one for each boardgame player.

My primary goal is to have these two devices communicating silently, when the two wargamers enjoy their play.
This companion App is almost done. I only need to be able to have the Android Tablets communicate.

Hence my secondary goal :
In order to learn how to do it, I went to designing a Client-Server Chat App from the ground up.
I already programmed a Stack which is completly functionnal when the Server is on PC, and the Clients share a lot of platforms ( PC, Android Device, ...) all over a WIFI network. All is working fine.
For now I monitor in plain text all the transfers between the Clients. (Its easier to debug in plain text)
At this stage of my project, I am also able to transfer without problem a lot of complex datas, like Arrays and so.

My ultimate goal :
Having the 2 Tablets transfering datas on a WIFI network around the table.
Hence the idea of a Client-Server App I can utilize for transfering datas and the idea of "by-sockets transfers".

My project is well on course and nearly complete.
It can already be functionnal with 2 Android devices, and a Server on PC, on the WIFI LAN.
But I would rather have the satisfaction of forgetting the PC Server if I was able to have the Socket Server on one of the 2 Tablets.

The only problem is that my Android Tablets refuse to accept a Connection : I always receive the same Error : "Can't reuse port" !
Last edited by ChrisP on Wed Apr 29, 2020 7:21 am, edited 1 time in total.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Socket Server on an Android Device

Post by FourthWorld » Mon Apr 20, 2020 8:41 am

Sounds like a very cool project. So this is all in the LAN, yes? That simplifies things.

Do you have something else bound to that port?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

ChrisP
Posts: 4
Joined: Fri Apr 17, 2020 4:54 pm

Re: Socket Server on an Android Device

Post by ChrisP » Mon Apr 20, 2020 11:36 am

Nothing else is bound to that port and it's only on a LAN.
The sole issue is the Tablet not willling to accept connection on any port (because it "can't reuse the port").
My tests are showing up a brief instant where the Client can connect (sign of a beginning dialog where the client sees the Server Socket).
No reaction from the Server then. And nothing hereafter...

How can I send you my Client-Server Stack if you want to try it ?

ChrisP
Posts: 4
Joined: Fri Apr 17, 2020 4:54 pm

Re: Socket Server on an Android Device [BUG 22 718]

Post by ChrisP » Sat May 09, 2020 10:34 am

Hello guys,

The issue I dug up is now officialy referenced as an official BUG of the engine :


Bug 22718 - Android: accept connections can fail on some Android devices


2020-05-05 11:16:04 EDT

The "accept connections ... " command will fail with the error "can't reuse port"


This is due to an attempt to set the SO_REUSEPORT socket option on platforms where this option is not supported and affects Android devices with kernel version < 3_9.

The Development Team is on it and it won't be long since they find the patch, as usual.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Socket Server on an Android Device

Post by FourthWorld » Sun May 10, 2020 12:37 am

Thanks for the update. Chris.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply

Return to “Internet”