'TCPServer 'This sample shows how to use the Winsock control to talk to a device. 'You must have a licensed copy of the Winsock control 'See Tech Note 2 for more information on Microsoft's licenses. 'For real world apps, you'll want to do more error checking. 'Use this sample with the TcpClient samples that come in NS Basic/CE and 'NS Basic/Palm. AddObject "MSWinsock.Winsock","wsServer" AddObject "MSWinsock.Winsock","wsServer1" Sub cmdClear_Click() lbStatus.Clear End Sub Sub cmdClose_Click() Bye End Sub Sub Form1_Load() wsServer.localport=1010 wsServer.Listen getState End Sub Sub wsServer_Close lbStatus.AddItem ("Closed at " + Str(Time)) wsServer.Close getState End Sub Sub wsServer_ConnectionRequest(RequestID) getState lbStatus.addItem "Connection request received " & requestID wsServer1.Accept requestID lbStatus.AddItem "Connected " + wsServer.RemoteHostIP End Sub Sub wsServer1_DataArrival(bytesTotal) Dim strData getState lbstatus.additem "Bytes received: " & bytesTotal wsServer1.GetData strData, 8 lbStatus.AddItem "Received: " + strData 'Here is where you could do some processing of the data received. 'In this sample, we'll simply send the string back in upper case. wsServer1.SendData "Message from Server: " & ucase(strData) End Sub Sub wsServer_Error(Number, Description, Scode, Source, HelpFile, HelpContext, CancelDisplay) On Error Resume Next lbStatus.AddItem "WinSock error " & Description getState wsServer.Close End Sub Sub getState() Select Case wsServer.state Case 0: fldState.text="Closed" Case 1: fldState.text="Open" Case 2: fldState.text="Listening" Case 3: fldState.text="Connection Pending" Case 4: fldState.text="Resolving Host" Case 5: fldState.text="Host Resolved" Case 6: fldState.text="Connecting" Case 7: fldState.text="Connected" Case 8: fldState.text="Peer is closing" Case 9: fldState.text="Error" End Select doEvents End Sub '*** Begin Generated Code *** Const AppEXEName = "TCPServer" Const AppPath = "E:\NSBD1\Files\Samples\TCPServer.txt" Form1_Show 'Default Form Dim Form1_Temp Sub Form1_Show On Error Resume Next UpdateScreen If Not IsObject(Form1_Temp) Then AddObject "Form", "Form1", 0, 0, 322, 237 Form1.Visible = False Form1.Caption = "Form1" Set Form1_Temp = Form1 AddObject "Frame", "Frame1", 8, 8, 268, 152, Form1 Frame1.Caption = "Connection Status" Frame1.FontSize = 8.25 '-------- AddObject "ListBox", "lbStatus", 8, 16, 252, 95, Frame1 lbStatus.FontSize = 8.25 '-------- AddObject "TextBox", "fldState", 8, 124, 252, 20, Frame1 fldState.FontSize = 8.25 '-------- AddObject "CommandButton", "cmdClear", 64, 172, 64, 28, Form1 cmdClear.Caption = "Clear" cmdClear.FontSize = 8.25 '-------- AddObject "CommandButton", "cmdClose", 156, 172, 68, 28, Form1 cmdClose.Caption = "Close" cmdClose.FontSize = 8.25 '-------- End If Form1.Visible = True Form1_Load End Sub 'Form1_Show Sub Form1_Hide If Not IsObject(Form1_Temp) Then Err.Raise 44000, , "Form not loaded" Exit Sub End If On Error Resume Next Form1.Visible = False Form1_Unload End Sub 'Form1_Hide '*** End Generated Code ***