Sockets: Difference between revisions

3,241 bytes added ,  2 years ago
Example added in PDP-10 assembly (MACRO-10/TOPS-20).
m (→‎{{header|Phix}}: syntax coloured, marked p2js incompatible)
(Example added in PDP-10 assembly (MACRO-10/TOPS-20).)
Line 624:
sid:sendto( "hello socket world", host, port )
sid:close()</lang>
 
=={{header|MACRO-10}}==
<lang MACRO-10>
 
TITLE SOCKET
 
COMMENT !
 
Socket Example ** PDP-10 Assembly Language (KJX 2022)
Assembler: MACRO-10 Operating System: TOPS-20 V7
 
On TOPS-20, TCP-connections are made by opening a special
file on the "TCP:" device (in this case "TCP:256"). Apart
from the funky filename, there is virtually no difference
between opening files on disk and creating TCP-connections
or endpoints, so we go through the usual sequence of GTJFN
(= get file-handle), OPENF (open file), finally followed
by CLOSF (close file).
 
!
 
SEARCH MONSYM,MACSYM ;Load symbolic names for syscalls.
.REQUIRE SYS:MACREL
 
STDAC. ;Define standard register names.
 
JFN: BLOCK 1 ;File handle for TCP connection.
TCPFN: ASCIZ /TCP:256/ ;TCP "filename"
STR: ASCIZ /Hello World!/ ;String to send.
STRLEN= <.-STR>*5 ;Length of string.
 
GO:: RESET% ;Initialize process.
 
;; Get a file-handle (JFN) for the TCP-connection:
MOVX T1,GJ%SHT ;Do "short" GTJFN% call.
HRROI T2,TCPFN ;TCP "filename" into T2.
GTJFN% ;Get file-handle.
ERJMPS ERROR ; Handle errors.
MOVEM T1,JFN ;Store JFN we got.
 
;; Open the "file":
 
HRRZ T1,JFN ;File-handle without flags into T1.
MOVX T2,FLD(8,OF%BSZ)!OF%RD!OF%WR ;8bit bytes, read+write.
OPENF% ;Open file.
ERJMPS ERROR ; Handle errors.
 
;; Write the string.
 
MOVE T1,JFN ;File-handle into T1.
HRROI T2,STR ;String-pointer into T2.
MOVEI T3,STRLEN ;Length of string into T3.
SOUT% ;Write string.
ERJMPS ERROR ; Handle errors.
 
;; Close file.
 
HRRZ T1,JFN ;Get file-handle into T1.
CLOSF% ;Close file.
ERJMPS ERROR ; Handle errors.
 
;; End program.
 
RESET% ;Reset, to release JFN.
HALTF% ;Halt program.
JRST GO ;Allow for continue-command.
 
;;
;; ERROR: Print standardized error-message by means of ERSTR.
;; This is similar to perror() in C.
;;
 
ERROR: MOVEI T1,.PRIOU ;Print on standard output.
MOVE T2,[.FHSLF,,-1] ;Own process, last error.
SETZ T3 ;No length-limit on error msg.
ERSTR% ;Print error-message.
JFCL ; Ignore errors from ERSTR%.
JFCL ; Dito.
RESET% ;Reset, to release JFN.
HALTF% ;Halt program.
JRST GO ;Allow for continue-command.
 
END GO
</lang>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
Anonymous user