CloseTCPServer.htm 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <html>
  2. <head>
  3. <title>Blitz3D Docs</title>
  4. <link rel=stylesheet href=../css/commands.css type=text/css>
  5. </head>
  6. <body>
  7. <h1>CloseTCPServer serverhandle</h1>
  8. <h1>Parameters</h1>
  9. <table>
  10. <tr>
  11. <td>
  12. serverhandle = handle assigned when the server was created.
  13. </td>
  14. </tr>
  15. </table>
  16. <h1>Description</h1>
  17. <table>
  18. <tr>
  19. <td>
  20. Closes a TCP/IP server previously created with the CreateTCPServer command.
  21. </td>
  22. </tr>
  23. </table>
  24. <h1><a href=../2d_examples/CloseTCPServer.bb>Example</a></h1>
  25. <table>
  26. <tr>
  27. <td>
  28. ; CreateTCPServer, CloseTCPServer, AcceptTCPStream Example <br />
  29. ; This code is in two parts, and needs to be run seperately on the same machine <br />
  30. <br />
  31. ; --- Start first code set --- <br />
  32. ; Create a server and listen for push <br />
  33. <br />
  34. svrGame=CreateTCPServer(8080) <br />
  35. <br />
  36. If svrGame<>0 Then <br />
  37. Print "Server started successfully." <br />
  38. Else <br />
  39. Print "Server failed to start." <br />
  40. End <br />
  41. End If <br />
  42. <br />
  43. While Not KeyHit(1) <br />
  44. strStream=AcceptTCPStream(svrGame) <br />
  45. If strStream Then <br />
  46. Print ReadString$(strStream) <br />
  47. Delay 2000 <br />
  48. End <br />
  49. Else <br />
  50. Print "No word from Apollo X yet ..." <br />
  51. Delay 1000 <br />
  52. End If <br />
  53. Wend <br />
  54. <br />
  55. End <br />
  56. <br />
  57. ; --- End first code set --- <br />
  58. <br />
  59. <br />
  60. ; --- Start second code set --- <br />
  61. ; Copy this code to another instance of Blitz Basic <br />
  62. ; Run the above code first, then run this ... they will 'talk' <br />
  63. <br />
  64. ; Create a Client and push data <br />
  65. <br />
  66. strmGame=OpenTCPStream("127.0.0.1",8080) <br />
  67. <br />
  68. If strmGame<>0 Then <br />
  69. Print "Client Connected successfully." <br />
  70. Else <br />
  71. Print "Server failed to connect." <br />
  72. WaitKey <br />
  73. End <br />
  74. End If <br />
  75. <br />
  76. ; write stream to server <br />
  77. WriteString strmGame,"Mission Control, this is Apollo X ..." <br />
  78. Print "Completed sending message to Mission control..." <br />
  79. <br />
  80. ; --- End second code set --- <br />
  81. </td>
  82. </tr>
  83. </table>
  84. <br>
  85. <a target=_top href=../index.htm>Index</a><br>
  86. <br>
  87. Click <a href=http://www.blitzbasic.co.nz/b3ddocs/command.php?name=CloseTCPServer&ref=comments target=_blank>here</a> to view the latest version of this page online</body>
  88. </html>