BBC BASIC for Windows
« Server / Client »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 10:14pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Server / Client  (Read 399 times)
dfeugey
Guest
xx Re: Server / Client
« Reply #10 on: Jul 2nd, 2015, 4:55pm »

With the same receiver :

Code:
      INSTALL @lib$+"SOCKLIB"
      PROC_initsockets

      socket% = FN_tcpconnect(FN_gethostname, "12321")
      IF socket% <=0 ERROR 100, "Failed to open socket"

      REM Don't use FN_writesocket since an error is expected
      msg$ = "hello socket world"+CHR$13+CHR$10
      SYS `send`, socket%, !^msg$, LEN(msg$), 0 TO result%

      msg$ = CHR$13+CHR$10
      SYS `send`, socket%, !^msg$, LEN(msg$), 0 TO result%

      PROC_closesocket(socket%)
      PROC_exitsockets 

Works...

Code:
      INSTALL @lib$+"SOCKLIB"
      PROC_initsockets

      socket% = FN_tcpconnect("127.0.0.1", "12321")
      IF socket% <=0 ERROR 100, "Failed to open socket"

      REM Don't use FN_writesocket since an error is expected
      msg$ = "hello socket world"+CHR$13+CHR$10
      SYS `send`, socket%, !^msg$, LEN(msg$), 0 TO result%

      msg$ = CHR$13+CHR$10
      SYS `send`, socket%, !^msg$, LEN(msg$), 0 TO result%

      PROC_closesocket(socket%)
      PROC_exitsockets
 

Does not.

I'm not sure it's not linked to the fact that the DNS resolves localhost (and not the hosts file) or that my config is IPv6 or that I have a network bridge. Nota: ping localhost, or ping 127.0.0.1 do work.

Conclusion: don't rely on localhost under Windows. Many people seem to have similar problems.
« Last Edit: Jul 2nd, 2015, 5:01pm by dfeugey » User IP Logged

dfeugey
Guest
xx Re: Server / Client
« Reply #11 on: Jul 2nd, 2015, 5:08pm »

Quote:
So please correct it (that particular submission is not one of mine)!

It's not mine either. But it's now corrected.
User IP Logged

rtr2
Guest
xx Re: Server / Client
« Reply #12 on: Jul 2nd, 2015, 7:10pm »

on Jul 2nd, 2015, 4:55pm, dfeugey wrote:
With the same receiver

Do you literally mean "the same"? You need to change both ends to 'localhost' - you cannot establish a connection between localhost (which doesn't go through your firewall) and your host's actual name (which does). If you have been changing only one end that would explain the 'problem'.

For reference, this is the 'listener' program I have been using to test the Rosetta Code example:

Code:
      INSTALL @lib$+"SOCKLIB"
      PROC_initsockets
      ON CLOSE PROC_exitsockets : QUIT
      ON ERROR SYS "MessageBox", @hwnd%, REPORT$, 0, 0 : PROC_exitsockets : QUIT

      listen% = FN_tcplisten("localhost", "256")
      IF listen%<0 ERROR 100, "Couldn't open listening socket"
      REPEAT
        WAIT 1
        socket% = FN_check_connection(listen%)
      UNTIL socket%
      PRINT "Connection made"

      buffer$ = STRING$(256, CHR$(0))
      REPEAT
        WAIT 1
        result% = FN_readsocket(socket%, !^buffer$, LEN(buffer$) - 1)
        IF result% > 0 PRINT LEFT$(buffer$, result%)
      UNTIL result%=-1
      PRINT "Disconnected"

      PROC_closesocket(socket%)
      PROC_exitsockets
      END 

Richard.
User IP Logged

dfeugey
Guest
xx Re: Server / Client
« Reply #13 on: Jul 2nd, 2015, 8:53pm »

Ha ha, very good smiley
That was this, yes.

I never had the problem before, since Xojo use DNS, that supports/translates localhost. BBC4Win is definitively more bare metal. Not a bad thing.

This dual way is a very good way to secure accesses... as localhost is local only and gethostbyname a 'network-carded' version. But it will be a problem for a tool that must work both local and distant... Not a big deal, but good to know.

Thanks again for the tip.
« Last Edit: Jul 2nd, 2015, 8:56pm by dfeugey » User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls