Home   Arduino/PD   OpenRabbit   SWK-8630   TcpSrv   DV300F   Accumulator   Mail me 
I love Vim! 
It's not really possible to create a -simple- AND -robust- server using just Visual Basic. It will be either simple, and thus not stable, or robust and thus very complex.
So here is the sollution: TcpSrv (ActiveX TCP server)
I've made many simple programs using Visual Basic, using Visual Basic just as a glew-language. But many times I wanted to be able to have one or more clients logged on. So I've made TcpSrv. You're able to use Binary or ASCII mode. In binary mode it will just pass you a byte string of data with a length identfier. In ASCII mode it will return a null terminated line, but also the length is returend. The lines are split using a linefeed (carriage returns are discarded). A few simple events and methods to get control over the ActiveX object (written using the async socket class in C++).

  • Download TcpSrv here (includes a ready to use Visual Basic sample program)

    OnError(Description) This will return fatal error messages.
    OnWarning(Description) This will return non-fatal error messages (warnings).
    OnConnect(Index, IsLast) Every incomming connection will be accepted and reported using this event. When the connection buffer is full, the IsLast flag will be set to true. The server can then tell the client it's too busy and then close the connection using 'Close Index'. Also the GetInfo method can be used to determine the address and port from which the client made its connection. If the IP is invalid, the 'Close Index' method may also be used to reject the client.
    OnReceive(Index, Message, Length)     Every message (binary or ASCII) will be returned using this event. The message (null terminated for ASCII) will be stored in the byte string 'Message', for both types the length of the message is returned. In case of an ASCII message the carriage return and linefeed will be discarded. Every line is recognized by its linefeed.
    OnClose(Index) When a client has closed the connection, the OnClose event is raised. The GetInfo method may still be used to determine the origin of the client for fancy logging :-)

    Bind [Port] To make the server bind the socket and listen for incomming connections, this method must be called. Optionaly a Port may be specified. The port can also be set using the Port property.
    UnBind This method may be used to shut the server down. It's not necesery to close the client connections prior to calling this method. But if you want to be nice to your clients, you will tell them the server will go down :-)
    GetInfo(Index, Host, Port) Call this function with a valid index and a pre-allocated Host and Port variable. After the call the Host and Port variables will contain the source address of the client.
    IsConnected Use this method to check wether or not a client is connected.
    bytesReceived(Index) A counter for the total amount of bytes received from a specific client.
    bytesSend(Index) A counter for the total bytes send to a specific client.
    Close(Index) This method closes the connection to a client.

    Port Use this to set the port which the server has to listen to. It's exactly the same as calling Bind with an argument.
    Binary Set to true, the server enters binary mode and will pass the data exactly as it is. Set to false, the server enters ASCII mode and will pass lines of data, split over linefeeds (\n 0xA). Carriage (\r 0xD) returns will be discarded.

    © 2003-2011 by Lourens Rozema