Author |
Topic: Server / Client (Read 399 times) |
|
dfeugey
Guest
|
 |
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 » |
Logged
|
|
|
|
dfeugey
Guest
|
 |
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.
|
|
Logged
|
|
|
|
rtr2
Guest
|
 |
Re: Server / Client
« Reply #12 on: Jul 2nd, 2015, 7:10pm » |
|
on Jul 2nd, 2015, 4:55pm, dfeugey wrote: 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.
|
|
Logged
|
|
|
|
dfeugey
Guest
|
 |
Re: Server / Client
« Reply #13 on: Jul 2nd, 2015, 8:53pm » |
|
Ha ha, very good  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 » |
Logged
|
|
|
|
|