Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
|
Accept Connection on SocketDemonstrates how to create a TCP/IP socket, listen on a port, accept an incoming connection, and send a "Hello World" message to the client.
LOCAL loListenSocket LOCAL lnSuccess LOCAL loConnectedSocket loListenSocket = CreateObject('Chilkat.Socket') lnSuccess = loListenSocket.UnlockComponent("Anything for 30-day trial") IF (lnSuccess <> 1) THEN =MESSAGEBOX("Failed to unlock component") QUIT ENDIF * Bind to a port and listen for incoming connections: * This example will listen at port 5555 and allows for a backlog * of 25 pending connection requests. lnSuccess = loListenSocket.BindAndListen(5555,25) IF (lnSuccess <> 1) THEN =MESSAGEBOX(loListenSocket.LastErrorText) QUIT ENDIF * Get the next incoming connection * Wait a maximum of 20 seconds (20000 millisec) loConnectedSocket = loListenSocket.AcceptNextConnection(20000) IF (loConnectedSocket = NULL ) THEN =MESSAGEBOX(loListenSocket.LastErrorText) QUIT ENDIF * Set maximum timeouts for reading an writing (in millisec) loConnectedSocket.MaxReadIdleMs = 10000 loConnectedSocket.MaxSendIdleMs = 10000 * Send a "Hello World!" message to the client: lnSuccess = loConnectedSocket.SendString("Hello World!") IF (lnSuccess <> 1) THEN =MESSAGEBOX(loConnectedSocket.LastErrorText) RELEASE loConnectedSocket QUIT ENDIF * Close the connection with the client. * Wait a max of 20 seconds (20000 millsec) loConnectedSocket.Close(20000) =MESSAGEBOX("success!") |
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.
Mail Component · .NET Email Component · ASP Mail Component · XML Parser