CreateTCPServer.htm 2.3 KB

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