Telnet two devices at the same time 1 C# program

Hi, currently I have one 100% working program used to telnet my Arduino circuit.
I use this C# class found somewhere around the web: Anyway, without this forum, I wouldn't be able to finish my program.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Sockets;
namespace USSR
enum Verbs
WILL = 251,
WONT = 252,
DO = 253,
DONT = 254,
IAC = 255
enum Options
SGA = 3
class TelnetConnection
TcpClient tcpSocket;
int TimeOutMs = 100;
public TelnetConnection(string Hostname, int Port)
tcpSocket = new TcpClient(Hostname, Port);
public string Login(string Username, string Password, int LoginTimeOutMs)
int oldTimeOutMs = TimeOutMs;
TimeOutMs = LoginTimeOutMs;
string s = Read();
if (!s.TrimEnd().EndsWith(":"))
throw new Exception("Failed to connect : no login prompt");
WriteLine(Username);
s += Read();
if (!s.TrimEnd().EndsWith(":"))
throw new Exception("Failed to connect : no password prompt");
WriteLine(Password);
s += Read();
TimeOutMs = oldTimeOutMs;
return s;
public void WriteLine(string cmd)
Write(cmd + "\n");
public void Write(string cmd)
if (!tcpSocket.Connected) return;
byte[] buf = System.Text.ASCIIEncoding.ASCII.GetBytes(cmd.Replace("\0xFF", "\0xFF\0xFF"));
tcpSocket.GetStream().Write(buf, 0, buf.Length);
public string Read()
if (!tcpSocket.Connected) return null;
StringBuilder sb = new StringBuilder();
do
ParseTelnet(sb);
System.Threading.Thread.Sleep(TimeOutMs);
} while (tcpSocket.Available > 0);
return sb.ToString();
public bool IsConnected
get { return tcpSocket.Connected; }
void ParseTelnet(StringBuilder sb)
while (tcpSocket.Available > 0)
int input = tcpSocket.GetStream().ReadByte();
switch (input)
case -1:
break;
case (int)Verbs.IAC:
// interpret as command
int inputverb = tcpSocket.GetStream().ReadByte();
if (inputverb == -1) break;
switch (inputverb)
case (int)Verbs.IAC:
//literal IAC = 255 escaped, so append char 255 to string
sb.Append(inputverb);
break;
case (int)Verbs.DO:
case (int)Verbs.DONT:
case (int)Verbs.WILL:
case (int)Verbs.WONT:
// reply to all commands with "WONT", unless it is SGA (suppres go ahead)
int inputoption = tcpSocket.GetStream().ReadByte();
if (inputoption == -1) break;
tcpSocket.GetStream().WriteByte((byte)Verbs.IAC);
if (inputoption == (int)Options.SGA)
tcpSocket.GetStream().WriteByte(inputverb == (int)Verbs.DO ? (byte)Verbs.WILL : (byte)Verbs.DO);
else
tcpSocket.GetStream().WriteByte(inputverb == (int)Verbs.DO ? (byte)Verbs.WONT : (byte)Verbs.DONT);
tcpSocket.GetStream().WriteByte((byte)inputoption);
break;
default:
break;
break;
default:
sb.Append((char)input);
break;
My UI Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net.Sockets;
namespace USSR
public partial class mainForm : Form
TelnetConnection tc;
public bool keyPressChecker = false;
public bool connectedChecker = false;
public mainForm()
InitializeComponent();
// webBrowser1.Navigate("http://admin:[email protected]");
this.tc = null;
this.connectedChecker = false;
private void radioButton2_CheckedChanged(object sender, EventArgs e)
try
if (submarineRadioBtn.Checked)
System.Diagnostics.Process.Start("dummySub.exe");
catch (Exception ex)
MessageBox.Show(ex.ToString());
private void centerBtnCamera_Click(object sender, EventArgs e)
private void forwardBtn_Click(object sender, EventArgs e)
if (connectedChecker)
this.tc.WriteLine("W");
private void connectToolStripMenuItem1_Click(object sender, EventArgs e)
try
//create a new telnet connection
tc = new TelnetConnection("192.168.0.102", 23);
if (tc.IsConnected)
connectedChecker = true;
catch (Exception ex)
MessageBox.Show(ex.ToString());
private void controlKeyDownCheckBox_CheckedChanged(object sender, EventArgs e)
if (controlKeyDownCheckBox.Checked == true)
keyPressChecker = true;
else
keyPressChecker = false;
private void controlKeyDownCheckBox_KeyDown(object sender, KeyEventArgs e)
if (keyPressChecker == true)
if (e.KeyCode == Keys.W)
if (connectedChecker)
tc.WriteLine("W");
if (e.KeyCode == Keys.S)
if (connectedChecker)
tc.WriteLine("S");
private void reverseBtn_Click(object sender, EventArgs e)
if (connectedChecker)
tc.WriteLine("S");
private void disconnectToolStripMenuItem_Click(object sender, EventArgs e)
try
tc = null;
connectedChecker = false;
catch (Exception ex)
MessageBox.Show(ex.ToString());
private void controlKeyDownCheckBox_KeyUp(object sender, KeyEventArgs e)
if (keyPressChecker == true)
if (e.KeyCode == Keys.W)
if (connectedChecker)
tc.WriteLine("O"); //decrease to MID PT.
if (e.KeyCode == Keys.S)
if (connectedChecker)
tc.WriteLine("P"); //decrease speed to MID PT.
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
Application.Exit();
Now, what I want to know is this: IS IT POSSIBLE FOR MY C# PROGRAM TO TELNET TWO DEVICES AT THE SAME TIME? 
Thanks
Glenn

try this links :
http://www.codeproject.com/Articles/19071/Quick-tool-A-minimalistic-Telnet-library
http://stackoverflow.com/questions/25116077/send-and-receive-commands-via-telnet-in-c-sharp
http://stackoverflow.com/questions/12283241/ssh-to-server-then-telnet-to-device

Similar Messages

  • Talking to two devices, at the same time.

    Hi,
    I wonder you could help me with my solution.
    I'm using GPIB to talk to two devices. I need to reset and align one device A and control the device B. The process A can take up to 2 minutes. The process B is to cool off the DUT to demanded temperature and it can take up to 3 minutes to achieve the demanded temperature. To monitor these processes I use pull method and:
    for process A I use the STATPER:COND? query (is it 1?)
    for process V I use TEMP? query (get temperature, is the answer within the limits to exit?)
    Now, I do these processes one by one. But, because both the processes have to be done each time before DUT is tested (as a part of a setting up the test routine), I'd like to save some test time. Technically, both two processes are independent, I can trigger them almost at the same time and wait when the longer one finishes itself, and them move to the tests part.
    However, the first attempt of doing go was unsuccessful. When I issued the STATPER:COND? query within the connection to the device A it looks like all GPIB bus is blocked and I cannot issue the TEMP? query to the device B, as the bus seems to be waiting for the STATPER:COND? command sent to the device A to finish.
    Strange thing is that then I issue the STATPER:COND? command for first time, the device is not able to accept any other commands.
    Why?
    What is proper approach to to this test time saving?
    Solved!
    Go to Solution.

    X-Series Signal Analyzer Spectrum Analyzer Mode User's and Programmer's Reference is to be downloaded from the web.
    below are some exerpts from this manual
    you can query and interpret the details with visa write and reads and a bit of bit analysing. I have no time to search for a working example.
    How to Use the Status Registers
    A program often needs to be able to detect and manage error conditions or changes in instrument status. There are two methods you can use to programmatically access the information in status registers:
    • The polling method
    • The service request (SRQ) method
    In the polling method, the instrument has a passive role. It only tells the controller that conditions have changed when the controller asks the right question. The polling method works well if you do not need to know about changes the moment they occur. To detect a change using the polling method, the program must repeatedly read the registers.
    To monitor a condition:
    a.Determine which register contains the bit that reports the condition.
    b.Send the unique SCPI query that reads that register.
    c.Examine the bit to see if the condition has changed.
    To query the status byte register, send the command *STB? The response will be the decimal sum of the bits which are set to 1. For example, if bit number 7 and bit number 3 are set to 1, the decimal sum of the 2 bits is 128 plus 8. So the decimal value 136 is returned. The *STB command does not clear the status register. In addition to the status byte register, the status byte group also contains the service request enable register. This register lets you choose which bits in the status byte register will trigger a service request.
    Send the *SRE <integer> command where <integer> is the sum of the decimal values of the bits you want to enable plus the decimal value of bit 6. For example, assume that you want to enable bit 7 so that whenever the standard operation status register summary bit is set to 1 it will trigger a service request. Send the command
    greetings from the Netherlands

  • Bluetooth - Connecting two devices at the same time on a Run (Bluetooth Mot headset

    I would like to connect two Bluetooth devised at the same time on my runs.  (Bluetooth Motorola headset (S10-HD) and Polars heart monitor (H7) at the same time)  is that possible? 

    fitnessdr wrote:
    Thank you for the information.  So if I were to return the new bluetooth keyboard, should I purchase the "Palm 3169WWZ Wireless Keyboard", or is there another model I should be looking for?  (From what I can tell, I believe this one will use IR.)
    THANKS!
    Correct, that's the one I use. 
    Be sure to download the newest driver (1.13) for the keyboard from the Palm Support pages for the keyboard:
    http://kb.palm.com/wps/portal/kb/na/keyboards/palmuniversalwirelesskeyboard/unlocked/downloads/page_...
    Do not install the driver that comes with the device on the disk - 1.13 is designed for the TX and fixes a bug that existed in the original driver.
    WyreNut
    I am a Volunteer here, not employed by HP.
    You too can become an HP Expert! Details HERE!
    If my post has helped you, click the Kudos Thumbs up!
    If it solved your issue, Click the "Accept as Solution" button so others can benefit from the question you asked!

  • Can I sync two devices at the same time?

    I have an iphone and an itouch. Can I plug them both into my imac at the same time?

    skevinti wrote:
    I have an iphone and an itouch. Can I plug them both into my imac at the same time?
    not recommended !
    try and find out @ your own peril
    JGG

  • Can one iTunes Radio account be used on more than one device at the same time?

    With an iTunes Match account, can ad-free iTunes Radio be used on two devices at the same time on that same account?

    Hi,
    Yes.
    Jim

  • Run two VIs at the same time

    Hello!
    I want to know how i can run two VIs at the same time.
    I mean that i want to run a second VI ( N.2) while another VI (N.1) is in
    execution without suspend it (N.1)
    If anyone has suggestions, please help me!
    Thank you very much.
    roby.

    If you say "run a vi", I assume that you have the VI open in LabVIEW, then press the run button. (Some of the earlier answers taks about programmatically calling VIs, which I don't think is the focus of your question)
    You can run as many VIs as you want at the same time. Simply press the run button of the second VI and they will both run.
    Of course you should ensure that they don't use the same resources (e.g. DAQ device, or listen on the same TCP port, etc.) In these cases, the second VI might fail. (Also if the second VI is a subVI of the first VI, you won't be able to run it seperately, because it will be already running.)
    LabVIEW Champion . Do more with less code and in less time .

  • Generat two signals at the same time and reading voltage

    Hii
    i have try to generate two signals at the same time and read voltage from another port on the board(not have to be at the same time), i have not alot of expriens in labview
    and i based my code of example(http://zone.ni.com/devzone/cda/epd/p/id/5197) from yours site and try to suit to my needs
    now my problem is when i generat the 2 signals(that work perfect) i canot read voltage from another port on my CB-68LP
    i can not find the problem  and make it over i hope there is away to figer out and fix it.
    i have two cards 6229, and two CB-68LP board.
    labview 8.5.
    my code is look like this - http://img142.imageshack.us/my.php?image=scrennshot2no2.png
    (this works perfect).
    and this is my code after suit to my need - http://img183.imageshack.us/my.php?image=scrennshotfl5.png,there is  error exception at  the right side.
    the exception-
    Possible reason(s):
    Specified route cannot be satisfied, because it requires resources that are currently in use by another route.
    Property: RefClk.Src
    Source Device: Dev1
    Source Terminal: 10MHzRefClock
    Required Resources in Use by
    Task Name: _unnamedTask<0>
    Source Device: Dev1
    Source Terminal: None
    Destination Device: Dev1
    Destination Terminal: RefClock
    Task Name: _unnamedTask<1>
    eyal

    sorry...
    The AO tasks is very important they will be synchronize ,it is very importent the two tasks will start at the same time
    and after it run at synchronize mode i will need to make reading of voltage
    i gust try to make simulation of machin (i give that machin AO and reading from it voltage that all)
    first of all i make the two signals(synchronize signals).
    and after it i will need to reading voltage.
    i can make two signals synchronize together.
    i can make reading voltage
    but i can't make two signals synchronize together with reading voltage
    it throw to me this error message.
    i am looking for away to figer this out.
    thank's for any help 
    eyal
    Attachments:
    test11.vi ‏130 KB

  • Write a progarm to test two parts at the same time

    Hi:
    I need to write a program in LabView that is capable of testing two parts at the same time.
    Explanation:
    I star the test on a unit, once all the electrical test is done move that unit to the pressure test without loosing the current test information and continue the test of the unit thewn generate a serial number only if it passes all the test. Then while the previous unit is going thru the pressure test star testing another unit for the elecrical test and so on.
    I am using LabView 2012

    From what you have described, I agree with what has been answered above. TestStand is specifically designed for. If you would like to provide more information about your application we could give you a more detailed response. For more information about TestStand follow this link
    www.ni.com/teststand
    Ryan
    Ryan
    Applications Engineer
    National Instruments

  • Is there a way to show two angles at the same time in the final edit rather than switch between them with Multicam?

    Can I show two angles at the same time in the final edit rather than alternate with Multicam?

    Stack two clips on top of each other and reduce the sizes. I think that's what you want.

  • TS2972 I would like to share my iTunes libraries with my Apple TV from both my iMac and Macbook Pro, but I use the same iTunes account on both devices. Is it possible to link my Apple TV to both devices at the same time?

    I recently purchased an Apple TV, and I currently have it linked to my iMac with my iTunes account. I also have a newer MacBook Pro that has some different iTunes media on it than my iMac does, but they share iTunes accounts. Is it possible to link both devices at the same time, have access to media on both computers, and use the same iTunes account on both computers?? It seems Apple TV will only link to one iTunes account per computer, but can access multiple computers if different iTunes accounts are activated on those computers.

    You can share multiple libraries with the Apple TV, they don't even need to use the same iTunes account. Just make sure that you use the same ID for homesharing on all devices.

  • Can i set up my iPad and iPod to use iMessage between the two devices with the same Apple ID?

    Can i set up my iPad and iPod to use iMessage between the two devices with the same Apple ID? SO i could iMessage if out from my iPod to my iPad at home to be viewed by a family member?

    Look into using Apple Configurator.  It's the easiest way to "reimage" and Manage iPads that I know of right now. 
    http://itunes.apple.com/us/app/apple-configurator/id434433123?mt=12
    Also, look into using the Educational Volume Purchase Program, if you have not already done so. 
    http://www.apple.com/education/volume-purchase-program/

  • Can I use more than one blue-tooth device at the same time on IPhone 4S? Like a wireless headsets and speed and cadence sensor for cycling computer, receive the data and listen music simultaneously

    Can I use more than one blue-tooth device at the same time on IPhone 4S? Like a wireless headsets and speed and cadence sensor for cycling computer, receive the data and listen music simultaneously

    As long as the profiles are different (ex. HID vs AD2P) you will not have any issues. But say if you try to use 2 keyboards at once, it won't work. Or 2 headsets at once. Your scenario seems fine.

  • HT204053 can two devices share the same apple id

    can two devices share the same apple id

    Yes.
    According to this Support Article  >  http://support.apple.com/kb/HT4627
    Your Apple ID can have up to 10 devices and computers (combined) associated with it.

  • One again, "can I use CC on two computers at the same time?" - in practice.

    I know this has been asked before and all those threads are locked. Many asked the question, but I haven't found a satisfying answer yet.
    Can I multi task with CC?
    I want to have my laptop next to my desktop. And while I render, export or whatever my newly shot documentary on the laptop I want to work with a music video project on my desktop. Then when the render is finished I render the music video and go back to the laptop and continue on the documentary. Or maybe I just work 5 minutes on the desktop music video, then come up with something brilliant for the project on the laptop and switch. Back and forth. Will that kind of activity result in any kind of limitation, usage-wise?
    So, working on Premiere on my two computers at the same time.. is it possible? Technically? I know the EULA says "only one person". But will it let one person mutli task?
    I need to know this before I buy. sorry for asking this again, please bless me with a clear answer

    Hi Jimmy Crim,
    Yes in case of Creative cloud subscription you are allowed to install and use the cc apps in any two machines.
    Even if you want you care allowed to use these apps together in both the machines.
    Thanks
    Kapil

  • Can I access two websites at the same time?

    Does Dreamweaver have the ability to open two websites at the same time?
    I basically have a CMS hosted on one server, that connects to my clients sites on other servers. I want to be able to open files on one server and edit them and also edit files on another server at the same time.
    If this isn't available in Dreamweaver, then I think it should be. I often need to copy code from one page in a site to another page in different site. To have the ability to have two windows open, each connected to a different website server would be invaluable to me. By having separate windows, each can have its own server connection. I don't know how easy that would be, but I'd love it!
    Cheers
    Glynn

    You can only connect to one site at a time.  And you need to edit files locally, save & then upload to the remote server.   AFAIK, no single FTP app is capable of connecting to more than one server at a time.  You might be able to do what you want with DW open and an additional 3rd party FTP client like Filezilla, each connecting to different servers.
    Nancy O.

Maybe you are looking for

  • Debayer Settings not Working??

    I've had a thread going over on RedUser here: http://www.reduser.net/forum/showthread.php?72431-Premiere-Media-Encoder-Render-Tests-Matr ox-CompressHD-Card-Results Basically in the source settings for any .r3d file in Premiere, you can choose High, M

  • SQl loader not loading records

    I have my control file like this options (skip=1) LOAD DATA INFILE xxx.csv into table xxx TRUNCATE FIELDS TERMINATED BY ',' optionally enclosed by '"'      RECORD_STATUS,      ITEM_NUMBER, Sql loader not loading records and giving error like .......

  • List the base tables of a view

    Hi All, I have a view but I do not have any information about the base tables and the query that was used to set up this view. Is there a way to atleast list the base tables on which the view was created! Thanks in advance! ~

  • Installation Crystal Report Server

    Hello, Any one can me provide any document related to that how we install Crystal Report Server 2008 and client ? i have no idea that what will be installation step and what will the prerequisition ? Thanks & Regard Manvendra

  • Call java code on submit anyaction on the BPEL form

    Dear All As you know in the BPEL form there is many action like Submit , Approve , Not Approve etc.. i want to call java code when i call any actions. Regards Wish79