Could someone point me in the right direction of how to use the FN_writesocket function from the Socket Library? The BBC for SDL wiki says:
FN_writesocket writes data to a connected socket. It takes three parameters: the socket number (as returned from FN_tcpconnect or FN_check_connection), the address of a buffer containing the data, and the length of the data in bytes. If the function succeeds it returns the number of bytes sent.
I have FN_writelinesocket working no problem, but can't figure out how to load a file in to the buffer to use FN_writesocket to send to the socket.
Also to receive input from the socket I'm using the following, which works but there is no local echo...is there a better way to do this so that the user can see what they're typing without having to enable local echo on their telnet client?
vela025 wrote: ↑Thu 08 Feb 2024, 11:14
I have FN_writelinesocket working no problem, but can't figure out how to load a file in to the buffer to use FN_writesocket to send to the socket.
Have you looked at the supplied example programs client.bbc and server.bbc, which illustrate the use of TCP sockets for a simple 'chat' application? You might also want to check out BBSterm.bbc and telstar.bbc which are complete telnet clients for IP Bulletin Boards and Videotex services respectively. All these programs are in the examples/general/ directory.
If you can't find the answer to your question there, please ask again.
vela025 wrote: ↑Thu 08 Feb 2024, 11:14
I have FN_writelinesocket working no problem, but can't figure out how to load a file in to the buffer to use FN_writesocket to send to the socket.
Have you looked at the supplied example programs client.bbc and server.bbc, which illustrate the use of TCP sockets for a simple 'chat' application? You might also want to check out BBSterm.bbc and telstar.bbc which are complete telnet clients for IP Bulletin Boards and Videotex services respectively. All these programs are in the examples/general/ directory.
If you can't find the answer to your question there, please ask again.
Hi yes I have looked at both of these, however chat and server both make use of fn_writelinesocket which as I say I have no problem using. I'm specifically asking about FN_writesocket. I have now seen their use in BBS Term and Telstar so will try to work from those examples.
Thanks
Last edited by vela025 on Thu 08 Feb 2024, 16:42, edited 1 time in total.
def procout(s$)
local R%
if s$="" endproc
R% = fn_writesocket(Socket%, ptr(s$), len(s$))
if R% < 0 then procerror("Send failed")
endproc
Where as I need it to send the contents of a file. So I've been unsucessfully trying to adapt what I have on my BBC (as I'm trying to port the BBS it runs to BBC Basic SDL). My thought was to read the data a bit at a time and send that, but I'm sure I read that BBC Basic SDL buffers the whole file and then sends that, rather than a bit at a time...but I'm a little stuck!
defprocd(file$)
local R%
in%=openin(file$):if in%=0:endproc
n%=0:repeat:pr$=bget#in%:R% = fn_writesocket(socket%, ptr(pr$), 5)):n%=n%+1 until n%=400 or eof#in%
close#in%
endproc
This is the code I'm trying to adapt from the original BBC Basic to send the menu files over tcp (which currently sends over serial then tcpser sends over tcp):
DEFPROCVA(n$):LOCALq,r:q=OPENINn$:IFq=0 THEN VDM%=FALSE
IF VDM% = FALSE ENDPROC
JJ%=q:REPEATr=BGET#q:VDUr:IFr=13VDU10
UNTILEOF#q:JJ%=0:CLOSE#q:PROCW:ENDPROC
vela025 wrote: ↑Thu 08 Feb 2024, 16:40
In both examples FN_writesocket is being used to send the contents of a string:
Where as I need it to send the contents of a file.
Presumably you want to split the file into reasonably small packets in order to send it using FN_writesocket() so I would expect you to be using code similar to the following (untested):
vela025 wrote: ↑Thu 08 Feb 2024, 16:40
In both examples FN_writesocket is being used to send the contents of a string:
Where as I need it to send the contents of a file.
Presumably you want to split the file into reasonably small packets in order to send it using FN_writesocket() so I would expect you to be using code similar to the following (untested):
vela025 wrote: ↑Thu 08 Feb 2024, 11:14
Also to receive input from the socket I'm using the following, which works but there is no local echo...is there a better way to do this so that the user can see what they're typing without having to enable local echo on their telnet client?
DEFPROCr(r$)
send%=FN_writelinesocket(socket%,r$) ;sends the quesiton
a%= FN_readlinesocket(socket%,maxtime%,r$)
a$=r$
ENDPROC
I've looked through the examples but as the BBS and Telstar examples are clients rather than servers I couldn't see how to achieve this as for those examples the users input goes in to the BBC Basic console window rather than the telnet session.
vela025 wrote: ↑Thu 08 Feb 2024, 20:21
Also to receive input from the socket I'm using the following, which works but there is no local echo...is there a better way to do this so that the user can see what they're typing without having to enable local echo on their telnet client?
Do you want the server to echo character by character back to the client, so that the person typing sees it appear as he types, just like a local echo? To achieve that you would presumably have to send (and echo) packets containing just a single character, not an entire line.
You would also have to take care to support input editing, for example the user typing 'backspace' and the server keeping track of the edits, so that what the user sees on his terminal is always the same as what the server has in its buffer.
Hated Moron wrote: ↑Thu 08 Feb 2024, 21:14
Do you want the server to echo character by character back to the client, so that the person typing sees it appear as he types, just like a local echo? To achieve that you would presumably have to send (and echo) packets containing just a single character, not an entire line.
You would also have to take care to support input editing, for example the user typing 'backspace' and the server keeping track of the edits, so that what the user sees on his terminal is always the same as what the server has in its buffer.
Yes that it what I was looking for. I'm beginning to think that it may be easier to implement using BBC Basic SDLs serial libraries and use tcpser in-between (as I do now). I was just hoping that by using tcp I could facilitate more than one user simultaneously. Thank you for your time, you've been incredibly helpful.
vela025 wrote: ↑Fri 09 Feb 2024, 15:58
I'm beginning to think that it may be easier to implement using BBC Basic SDLs serial libraries and use tcpser in-between (as I do now). I was just hoping that by using tcp I could facilitate more than one user simultaneously. Thank you for your time, you've been incredibly helpful.
Sending and receiving individual characters is straightforward (if wasteful of net bandwidth) and certainly you should be able to support multiple simultaneous users, the server_multi.bbc example program illustrates one way to do that. I can't see any difficulties with what you propose at all, so I must say I'm puzzled that you seem ready to give up.