fork download
  1. #include "hspsock.as"
  2.  
  3. #define ADDR "127.0.0.1"
  4. #define PORT 27182
  5. #define BUFSIZE 256
  6.  
  7. sdim send, BUFSIZE
  8. sdim recv, BUFSIZE
  9.  
  10. onexit *exit
  11.  
  12. button "SERVER", *sb
  13. button "CLIENT", *cb
  14. stop
  15.  
  16. *sb
  17. clrobj
  18. pos 0, 0
  19. mes "SERVER MODE"
  20.  
  21. *s
  22. mes
  23. sockmake 0, PORT
  24. if stat != 0 : ec = 1 : goto *se
  25.  
  26. repeat
  27. sockwait 0
  28. if stat != 1 : break
  29. wait 10
  30. loop
  31. if stat != 0 : ec = 2 : goto *se
  32.  
  33. send = strf("I'M A SERVER! @ %02d:%02d:%02d.%03d", gettime(4), gettime(5), gettime(6), gettime(7))
  34. sockput send, 0
  35. if stat != 0 : ec = 3 : goto *se
  36. mes "SEND: " + send
  37.  
  38. repeat
  39. sockcheck 0
  40. if stat != 1 : break
  41. wait 10
  42. loop
  43. if stat != 0 : ec = 4 : goto *se
  44.  
  45. sockget recv, BUFSIZE, 0
  46. if stat != 0 : ec = 5 : goto *se
  47. mes "RECV: " + recv
  48.  
  49. sockclose 0
  50. goto *s
  51.  
  52. *cb
  53. mes
  54. objenable 1, 0
  55. clrobj 0, 0
  56.  
  57. sockopen 0, ADDR, PORT
  58. if stat != 0 : ec = 1 : goto *ce
  59.  
  60. repeat
  61. sockcheck 0
  62. if stat != 1 : break
  63. wait 10
  64. loop
  65. if stat != 0 : ec = 2 : goto *ce
  66.  
  67. sockget recv, BUFSIZE, 0
  68. if stat != 0 : ec = 3 : goto *ce
  69. mes "RECV: " + recv
  70.  
  71. send = strf("I'M A CLIENT! @ %02d:%02d:%02d.%03d", gettime(4), gettime(5), gettime(6), gettime(7))
  72. sockput send, 0
  73. if stat != 0 : ec = 4 : goto *ce
  74. mes "SEND: " + send
  75.  
  76. sockclose 0
  77. objenable 1, 1
  78. stop
  79.  
  80. *se
  81. dialog "SERVER ERROR #"+ec, 1
  82. goto *exit
  83.  
  84. *ce
  85. dialog "CLIENT ERROR #"+ec, 1
  86. goto *exit
  87.  
  88. *exit
  89. sockclose 0
  90. end
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty