none
Connecting to Network device using W3Socket with Telnet - Multithreading RRS feed

  • Question

  • Hi,

    I am writing a C# program using the W3Socket.dll which:

    1. Connects to a network device Ex: Router with Telnet port 23

    2. Pass the credentials

    3. Execute a command and get the response in a string or a temp file.

    I am able to establish the connection and also able to key in the username and password. Further which I am checking for the prompt character and passing a command.

    I am not able to figure out as to how do I get the response of the command that I have passed.

    Any help would be appreciated.

    Thanks,


    Thursday, September 18, 2014 11:59 AM

Answers

  • Socket is a managed wrapper around the raw socket. If you cannot do it with Socket then it won't work with the raw socket either.  The Socket class doesn't have any support for messages because it is the raw socket. You have to implement the "command" logic yourself.  This is pretty much standard for any socket-based type.  How you implement the logic is dependent upon how the client-server system works.  In some cases you want a request-response system so the client and the server have to do handshaking.  In other cases the communication is bi-directional so you have to implement the same logic on both sides.  It depends upon your needs.

    Posting the code for a full client-server system is not possible in the forums.  There is too much code.  But there are plenty of examples available online that you can look at to determine how you want to implement it.  Google for "C# client server socket example".  Keep in mind that client-server systems need to be resilient to network errors so you'll have to bake in support for error detection, partial messages, no acknowledgements, etc.  There are entire books written on these topics.

    Finally, if you are going to use W3Socket then please post further questions in their forums.  They also might have example code for you to look at.

    Friday, September 19, 2014 3:25 PM
    Moderator

All replies

  • W3Sockets? This sounds like a third-party product.  These forums are for MS products. Please post questions related to third-party products on their forums. Alternatively, for socket communication just use the Socket or TcpClient classes in the core framework. 

    Michael Taylor
    http://blogs.msmvps.com/p3net

    Thursday, September 18, 2014 2:11 PM
    Moderator
  • Thanks for the quick reply.

    The Socket and TcpClient classes does not facilitate to issue the commands and get the output of the command.

    Could you please help me with a sample.

    Thanks

    Friday, September 19, 2014 5:36 AM
  • Socket is a managed wrapper around the raw socket. If you cannot do it with Socket then it won't work with the raw socket either.  The Socket class doesn't have any support for messages because it is the raw socket. You have to implement the "command" logic yourself.  This is pretty much standard for any socket-based type.  How you implement the logic is dependent upon how the client-server system works.  In some cases you want a request-response system so the client and the server have to do handshaking.  In other cases the communication is bi-directional so you have to implement the same logic on both sides.  It depends upon your needs.

    Posting the code for a full client-server system is not possible in the forums.  There is too much code.  But there are plenty of examples available online that you can look at to determine how you want to implement it.  Google for "C# client server socket example".  Keep in mind that client-server systems need to be resilient to network errors so you'll have to bake in support for error detection, partial messages, no acknowledgements, etc.  There are entire books written on these topics.

    Finally, if you are going to use W3Socket then please post further questions in their forums.  They also might have example code for you to look at.

    Friday, September 19, 2014 3:25 PM
    Moderator