Click here to Skip to main content
15,920,687 members
Home / Discussions / C#
   

C#

 
AnswerRe: Saving from one txt file into another one problem? Pin
Wayne Phipps31-Mar-07 10:25
Wayne Phipps31-Mar-07 10:25 
AnswerRe: Saving from one txt file into another one problem? Pin
Nader Elshehabi31-Mar-07 22:07
Nader Elshehabi31-Mar-07 22:07 
QuestionThe Form freeze ive tryed using threads but... nothing Pin
crazy friend31-Mar-07 8:07
crazy friend31-Mar-07 8:07 
AnswerRe: The Form freeze ive tryed using threads but... nothing Pin
Stanciu Vlad31-Mar-07 21:35
Stanciu Vlad31-Mar-07 21:35 
GeneralRe: The Form freeze ive tryed using threads but... nothing Pin
crazy friend1-Apr-07 19:14
crazy friend1-Apr-07 19:14 
GeneralRe: The Form freeze ive tryed using threads but... nothing Pin
HexaDeveloper2-Apr-07 12:30
HexaDeveloper2-Apr-07 12:30 
GeneralRe: The Form freeze ive tryed using threads but... nothing Pin
Stanciu Vlad3-Apr-07 3:33
Stanciu Vlad3-Apr-07 3:33 
GeneralRe: The Form freeze ive tryed using threads but... nothing Pin
crazy friend6-Apr-07 17:21
crazy friend6-Apr-07 17:21 
ok, that is what ive been trying... but i cant reach... look.... i already post my first code... i tried some other things like this


private void Form1_Load(object sender, System.EventArgs e)
{
Test.Socket_Server.CreateLabel(this);
System.Timers.Timer reloj = new System.Timers.Timer();
reloj.Enabled = true;
reloj.Interval = 1000;
reloj.Elapsed += new System.Timers.ElapsedEventHandler(reloj_Elapsed);

}

public void pintar()
{
//label1.Text = "voy a entrar del thread";
Socket_Server servi;
servi = new Socket_Server();
servi.Begin();
}
private void reloj_Elapsed(object sender, EventArgs e)
{
Socket_Server servi;
servi = new Socket_Server();
servi.Begin();
//Thread hilo = new Thread(new ThreadStart(pintar));
//hilo.IsBackground = true;
//hilo.Start();

}

as u can see i tried with a timer, and also with threads it seems like now the thread for the class Server (or the tcplistener) is running on the background... but... i cant make that the client send me his data..... its seems like the timer is ... looping... the thread... and itried alredy decrese the interval but nothing...

there is also a code in comment cause i tried just with the thread instead of the timer... but nothing... let me post all of the code... form, server class and client class...

Form*************
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;


namespace Test
{
///
/// Summary description for Form1.
///

///
public class Form1 : System.Windows.Forms.Form
{
private IContainer components;
private System.Windows.Forms.Button cmdserver;
private System.Windows.Forms.Button cmdclient;
public Socket_Server server;
private System.Windows.Forms.TextBox txtmsg;
private System.Windows.Forms.Label label1;
public Thread hilo;
public System.Threading.Timer reloj;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//

server = new Socket_Server();
}

///
/// Clean up any resources being used.
///

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.cmdserver = new System.Windows.Forms.Button();
this.cmdclient = new System.Windows.Forms.Button();
this.txtmsg = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// cmdserver
//
this.cmdserver.Location = new System.Drawing.Point(216, 120);
this.cmdserver.Name = "cmdserver";
this.cmdserver.Size = new System.Drawing.Size(75, 23);
this.cmdserver.TabIndex = 0;
this.cmdserver.Text = "Servidor";
this.cmdserver.Click += new System.EventHandler(this.cmdserver_Click);
//
// cmdclient
//
this.cmdclient.Location = new System.Drawing.Point(216, 176);
this.cmdclient.Name = "cmdclient";
this.cmdclient.Size = new System.Drawing.Size(75, 23);
this.cmdclient.TabIndex = 1;
this.cmdclient.Text = "Cliente";
this.cmdclient.Click += new System.EventHandler(this.cmdclient_Click);
//
// txtmsg
//
this.txtmsg.AcceptsReturn = true;
this.txtmsg.Location = new System.Drawing.Point(216, 84);
this.txtmsg.Name = "txtmsg";
this.txtmsg.Size = new System.Drawing.Size(280, 20);
this.txtmsg.TabIndex = 2;
this.txtmsg.Text = "txtmsg";
this.txtmsg.TextChanged += new System.EventHandler(this.txtmsg_TextChanged);
//
// label1
//
this.label1.Location = new System.Drawing.Point(213, 215);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(283, 102);
this.label1.TabIndex = 3;
this.label1.Text = "label1";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(512, 342);
this.Controls.Add(this.label1);
this.Controls.Add(this.txtmsg);
this.Controls.Add(this.cmdclient);
this.Controls.Add(this.cmdserver);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
this.PerformLayout();

}
#endregion

///
/// The main entry point for the application.
///

[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void Form1_Load(object sender, System.EventArgs e)
{
Test.Socket_Server.CreateLabel(this);
System.Timers.Timer reloj = new System.Timers.Timer();
reloj.Enabled = true;
reloj.Interval = 1000;
reloj.Elapsed += new System.Timers.ElapsedEventHandler(reloj_Elapsed);
}

private void cmdserver_Click(object sender, System.EventArgs e)
{
label1.Text = "ENTRANDO A SERVER";
server.Begin();
}

private void cmdclient_Click(object sender, System.EventArgs e)
{
}

private void txtmsg_TextChanged(object sender, EventArgs e)
{
}

public void pintar()
{
//label1.Text = "voy a entrar del thread";
Socket_Server servi;
servi = new Socket_Server();
servi.Begin();
}
private void reloj_Elapsed(object sender, EventArgs e)
{
Socket_Server servi;
servi = new Socket_Server();
servi.Begin();
//Thread hilo = new Thread(new ThreadStart(pintar));
//hilo.IsBackground = true;
//hilo.Start();


}

}
}

Server Class ***********

using System;
using System.Text;
using System.Net;
using System.Net.Sockets;

using System.Collections;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Globalization;

namespace Test
{
///
/// Summary description for Socket.
///

///

public class Socket_Server
{
private static Label label;

public Socket_Server()
{
//
// TODO: Add constructor logic here
//
}
public static void CreateLabel(Control Form1)
{
label=new Label();
label.Height=400;
label.Width=200;
label.Location = new Point(10,10);
label.Enabled = false;
label.Visible=true;
Form1.Controls.Add(label);
}
public void Begin()
{
try
{
IPAddress ipAd = IPAddress.Parse("192.168.1.100");
// use local m/c IP address, and
// use the same in the client

/* Initializes the Listener */
TcpListener myList=new TcpListener(ipAd,8002);

/* Start Listeneting at the specified port */
myList.Start();

label.Text=label.Text+"\r"+("The server is running at port 8001...");
label.Text=label.Text+"\r"+("The local End point is :" +
myList.LocalEndpoint );
label.Text=label.Text+"\r"+("Waiting for a connection.....");


Socket s=myList.AcceptSocket();
label.Text=label.Text+"\r"+("Connection accepted from " + s.RemoteEndPoint);

byte[] b=new byte[100];
int k=s.Receive(b);
label.Text=label.Text+"\r"+("Recieved...");
for (int i=0;i<k;i++)
label.text="label.Text+(Convert.ToChar(b[i]));

" asciiencoding="" asen="new" asciiencoding();
="" s.send(asen.getbytes("the="" string="" was="" recieved="" by="" the="" server."));
="" acknowledgement");
="" *="" clean="" up=""
="" s.close();
="" mylist.stop();
="" }
="" catch="" (exception="" e)="" {
="" "="" +="" e.stacktrace);
="" }
}

client="" class***********
using="" system;
using="" system.text;
using="" system.net;
using="" system.net.sockets;
using="" system.io;

using="" system.collections;
using="" system.drawing;
using="" system.componentmodel;
using="" system.windows.forms;
using="" system.data;
using="" system.globalization;



namespace="" test_ii
{
="" <summary="">
/// Summary description for Socket_Client.
///
public class Socket_Client
{
private static Label label;
public Socket_Client()
{
//
// TODO: Add constructor logic here
//
}
public static void CreateLabel(Control Form1)
{
label=new Label();
label.Height=400;
label.Width=200;
label.Location = new Point(10,10);
label.Enabled = false;
label.Visible=true;
label.AutoEllipsis = true; ;
Form1.Controls.Add(label);
}
public void Begin()
{
try
{
TcpClient tcpclnt = new TcpClient();
label.Text=label.Text+"\r"+("Connecting.....");

tcpclnt.Connect("192.168.1.100", 8002);
// use the ipaddress as in the server program

label.Text=label.Text+"\r"+("Connected");
label.Text=label.Text+"\r"+("Enter the string to be transmitted : ");

String str="KE ONGON";//Console.ReadLine();
Stream stm = tcpclnt.GetStream();

ASCIIEncoding asen= new ASCIIEncoding();
byte[] ba=asen.GetBytes(str);
label.Text=label.Text+"\r"+("Transmitting.....");

stm.Write(ba,0,ba.Length);

byte[] bb=new byte[100];
int k=stm.Read(bb,0,100);

for (int i=0;i
GeneralRe: The Form freeze ive tryed using threads but... nothing Pin
Stanciu Vlad6-Apr-07 23:22
Stanciu Vlad6-Apr-07 23:22 
Questionsteganography implemented in c sharp Pin
dhananjaysonar31-Mar-07 3:56
dhananjaysonar31-Mar-07 3:56 
AnswerRe: steganography implemented in c sharp Pin
Vasudevan Deepak Kumar31-Mar-07 4:25
Vasudevan Deepak Kumar31-Mar-07 4:25 
GeneralRe: steganography implemented in c sharp Pin
dhananjaysonar31-Mar-07 4:45
dhananjaysonar31-Mar-07 4:45 
GeneralRe: steganography implemented in c sharp Pin
Vega0231-Mar-07 6:29
Vega0231-Mar-07 6:29 
GeneralRe: steganography implemented in c sharp Pin
Colin Angus Mackay31-Mar-07 7:17
Colin Angus Mackay31-Mar-07 7:17 
AnswerRe: steganography implemented in c sharp Pin
Stefan Troschuetz31-Mar-07 5:49
Stefan Troschuetz31-Mar-07 5:49 
Questioninvoking a function with string[] Pin
ceken31-Mar-07 3:30
ceken31-Mar-07 3:30 
AnswerRe: invoking a function with string[] Pin
Leslie Sanford31-Mar-07 6:03
Leslie Sanford31-Mar-07 6:03 
GeneralRe: invoking a function with string[] Pin
ceken1-Apr-07 9:46
ceken1-Apr-07 9:46 
GeneralRe: invoking a function with string[] Pin
Leslie Sanford1-Apr-07 11:51
Leslie Sanford1-Apr-07 11:51 
QuestionCalling AddIn functions Pin
swje31-Mar-07 2:55
swje31-Mar-07 2:55 
AnswerRe: Calling AddIn functions Pin
Judah Gabriel Himango31-Mar-07 9:09
sponsorJudah Gabriel Himango31-Mar-07 9:09 
QuestionFileSize on a Website Pin
Kitchen_31-Mar-07 2:16
Kitchen_31-Mar-07 2:16 
AnswerRe: FileSize on a Website Pin
Dave Kreskowiak31-Mar-07 7:50
mveDave Kreskowiak31-Mar-07 7:50 
AnswerRe: FileSize on a Website Pin
Vasudevan Deepak Kumar1-Apr-07 5:32
Vasudevan Deepak Kumar1-Apr-07 5:32 
AnswerRe: FileSize on a Website Pin
Kitchen_1-Apr-07 14:30
Kitchen_1-Apr-07 14:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.