All pastes #236579 Raw Edit

Anonymous

public text v1 · immutable
·published 2006-11-03 21:55 UTC
rendered paste body
--------------------------form1-------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace blindfire
{
    public partial class fbf : Form
    {
        public fbf()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            bf test = new bf();
            test.setParams("smtp.ntic.qc.ca", 25, this); //not used yet
            test.makeConnect();
        }

        
        public void printText(string txt) {
            txtbox.Text = txt;
        }
    }
}
--------------------------ma classe-------------------------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.IO;
namespace blindfire
{
    class bf
    {

        private string server;
        private int port;
        Socket tcpClient = null;
        fbf Gui;
        private byte[] data = new byte[1024];


        public void setParams(string server, int port, fbf Gui)
        {
            this.server = server;
            this.port = port;
            this.Gui = gui;
        }

        public void makeConnect()
        {
            try {
                Socket newsock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                IPEndPoint iep = new IPEndPoint(IPAddress.Parse("205.236.172.181"), 25);
                newsock.BeginConnect(iep, new AsyncCallback(Connected), newsock);
                this.printText("Connecting... \r\n");
            } catch (Exception e) {
                Gui.BeginInvoke(printText, "Connection failed::" + e.Message);
            }
        }
        void Connected(IAsyncResult iar)
        {
            tcpClient = (Socket)iar.AsyncState;
            try
            {
                tcpClient.EndConnect(iar);
                printText("Connected to: " + tcpClient.RemoteEndPoint.ToString());
                tcpClient.BeginReceive(data, 0, 1024, SocketFlags.None, new AsyncCallback(ReceiveData), tcpClient);
            }
            catch (SocketException)
            {
                printText("Error connecting");
            }
        }
        void ReceiveData(IAsyncResult iar)
        {
            Socket remote = (Socket)iar.AsyncState;
            int recv = remote.EndReceive(iar);
            string stringData = Encoding.ASCII.GetString(data, 0, recv);
            printText(stringData);
        }
    }
}