All pastes #486555 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-05-13 23:02 UTC
rendered paste body
using System.Threading;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System;
using tcpClient;

public class Socket_init {
    frmMain fr;
    public Socket_init(frmMain fr) {
        this.fr = fr;
    }

	public void startInit(String ip){
        
		try{
            String responseData = String.Empty; // String to store the response ASCII representation.
			Byte[] data;

			TcpClient clientSocket = new TcpClient(ip,23);
			
			NetworkStream networkStream = clientSocket.GetStream();
			
			data = Encoding.ASCII.GetBytes("rocky\r");
			networkStream.Write(data,0,data.GetLength(0));
			data = Encoding.ASCII.GetBytes("pMA#iB45\r");
			networkStream.Write(data,0,data.GetLength(0));
            //fr.txtMain.Text = responseData;
            data = Encoding.ASCII.GetBytes("exit\r");
            networkStream.Write(data, 0, data.GetLength(0));
			
			while(true){
				data = new Byte[256];
				Int32 bytes = networkStream.Read(data, 0, data.Length); // Read the first batch of the TcpServer response bytes.
				responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);
                fr.setText(responseData);
                if (responseData.Equals("")) {
                    break;
                }
                responseData = String.Empty;
               
			}
		}
		catch (SocketException e)
		{
			Console.WriteLine("SocketException: {0}", e);
		}

	}
}