--------------------------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, ref textBox2); //not used yet test.makeConnect(); } } } --------------------------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; TextBox txtbox; private byte[] data = new byte[1024]; private void printText(string txt) { txtbox.Text = txt; } public void setParams(string server, int port, ref TextBox data) { this.server = server; this.port = port; this.txtbox = data; } 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) { this.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); } } }