Files
BlitzNext/_release/help/commands/2d_commands/CreateTCPServer.htm
T
2014-12-08 12:43:20 +13:00

92 lines
2.3 KiB
HTML

<html>
<head>
<title>Blitz3D Docs</title>
<link rel=stylesheet href=../css/commands.css type=text/css>
</head>
<body>
<h1>CreateTCPServer (port)</h1>
<h1>Parameters</h1>
<table>
<tr>
<td>
port = the port to use when creating the server
</td>
</tr>
</table>
<h1>Description</h1>
<table>
<tr>
<td>
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 />
<br />
Returns a TCP/IP server handle if successful or 0 if not.
</td>
</tr>
</table>
<h1><a href=../2d_examples/CreateTCPServer.bb>Example</a></h1>
<table>
<tr>
<td>
; CreateTCPServer, CloseTCPServer, AcceptTCPStream Example
<br />
; This code is in two parts, and needs to be run seperately on the same machine
<br />
<br />
; --- Start first code set ---
<br />
; Create a server and listen for push
<br />
<br />
svrGame=CreateTCPServer(8080)
<br />
<br />
If svrGame<>0 Then
<br />
Print "Server started successfully."
<br />
Else
<br />
Print "Server failed to start."
<br />
End
<br />
End If
<br />
<br />
While Not KeyHit(1)
<br />
strStream=AcceptTCPStream(svrGame)
<br />
If strStream Then
<br />
Print ReadString$(strStream)
<br />
Delay 2000
<br />
End
<br />
Else
<br />
Print "No word from Apollo X yet ..."
<br />
Delay 1000
<br />
End If
<br />
Wend
<br />
<br />
End
<br />
<br />
; --- End first code set ---
<br />
<br />
<br />
; --- Start second code set ---
<br />
; Copy this code to another instance of Blitz Basic
<br />
; Run the above code first, then run this ... they will 'talk'
<br />
<br />
; Create a Client and push data
<br />
<br />
strmGame=OpenTCPStream("127.0.0.1",8080)
<br />
<br />
If strmGame<>0 Then
<br />
Print "Client Connected successfully."
<br />
Else
<br />
Print "Server failed to connect."
<br />
WaitKey
<br />
End
<br />
End If
<br />
<br />
; write stream to server
<br />
WriteString strmGame,"Mission Control, this is Apollo X ..."
<br />
Print "Completed sending message to Mission control..."
<br />
<br />
; --- End second code set ---
<br />
</td>
</tr>
</table>
<br>
<a target=_top href=../index.htm>Index</a><br>
<br>
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>
</html>