|
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
|
|
|
|
|
Your freezing roblem arises from the Socket_Server.Begin() on the line Socket s=myList.AcceptSocket();
If you would have rode msdn for adtitional info about AcceptSocket[^] you would have realised that "AcceptSocket is a blocking method".
So in ordrer to avoid the client form from hanging you can use the Pending method that verifies if a client is present (method that does not block the thread), or simply move the whole code that blocks the form on a separate thread (call the procedure on a sperarate thread).
Good luck.
protected internal static readonly ... and I wish the list could continue ...
|
|
|
|
|
hey guys,
can any body implement the code given in the article in the following link.it's urgent guys!!!!!!!!!!
it makes use of asp.net and web service extension also.
link:-http://www.datastronghold.com/security-articles/general-security-articles/steganography-hiding-data-in-images.html
|
|
|
|
|
You can dynamically create images in C#/ASP.NET. CAPTCHA does that right?
|
|
|
|
|
but i want that code to be implemented for project so that i can send data in image for security purpose
|
|
|
|
|
dhananjaysonar wrote: but i want that code to be implemented for project so that i can send data in image for security purpose
Please note that security through obscurity[^] (including steganography) is generally a bad idea unless you're absolutely forced into using it.
That said, there is a wonderful series of articles here on CP that walks you through steganographic techniques. They can be found here[^].
|
|
|
|
|
Vega02 wrote: Please note that security through obscurity[^] (including steganography) is generally a bad idea unless you're absolutely forced into using it.
Only if it is used on its own. As part of a suite of security measures it can be beneficial.
|
|
|
|
|
dhananjaysonar wrote: can any body implement the code given in the article
There are probably some people that are able to implement this. The real question is: what are you willing to pay them for doing it or do you think someone will spent his freetime for doing your work.?
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Hi all,
I want to call a function with string[] using invoke method, but compiler gives an error message "Parameter count mismatch." When I try to invoke a function with int[], there is no problem. Any suggestion? Here is the code;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public delegate void TbWrite(string[] eMessage);
public TbWrite writeTb=null;
public Form1()
{
writeTb = new TbWrite(TbCallBack);
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string[] veri = new string[] { "data1", "data2" };
this.BeginInvoke(writeTb, veri);
}
public void TbCallBack(string[] mData)
{
textBox1.Text = mData[0];
textBox2.Text = mData[1];
}
}
}
Regards.
Cengiz EKEN
|
|
|
|
|
Check out the signature for Control.BeginInvoke Method (Delegate, Object[])[^]. Notice the second parameter. It's modified with the params keyword, which means that you can pass zero to many parameters in addition to the delegate.
(actually, if you don't pass any additional arguments to BeginInvoke , I'm assuming that Control.BeginInvoke Method (Delegate)[^] is called instead.)
So when you want to pass an array of strings to BeginInvoke , do this:
this.BeginInvoke(writeTb, new object { veri });
This makes the entire string array a single argument that can be passed to your callback method.
Now, why does the integer array work when the string array does not? I think it has to do with the string array being an array of reference types. The BeginInvoke method is seperating out, for lack of a better word, each element of the array and treating them as seperate objects instead of treating the array as a single object.
So the compiler is interpretting the call to BeginInvoke as:
this.BeginInvoke(writeTb, "data1", "data2");
Two parameters are getting passed to your callback instead of one, which is where the mismatch exception is being thrown.
I'm guessing that the reason that the integer array doesn't have the problem is that the compiler is treating it as one object.
|
|
|
|
|
Thank you for your explanatory answer, it wat too useful to understand the error, but there still some point. Here is the new question regarding this
When I changed the code as follows, it gives again the same error
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public delegate void TbWrite(object [] eMessage);
public TbWrite writeTb = null;
public Form1()
{
writeTb = new TbWrite(TbCallBack);
InitializeComponent();
}
public void TbCallBack(object [] mData)
{
textBox1.Text = mData.GetValue(0).ToString();
textBox2.Text = mData.GetValue(1).ToString();
}
private void button1_Click(object sender, EventArgs e)
{
object[] veri = new object[] { "data1", "data2" };
this.BeginInvoke(writeTb, veri );
}
}
}
|
|
|
|
|
ceken wrote: object[] veri = new object[] { "data1", "data2" };
This gives you a problem for the same reasons I described in my previous post. You need to wrap your array inside an object array so that it's treated as one object:
string[] veri = { "data1", "data2" };
this.BeginInvoke(writeTb, new object { ver });
The string array is placed in an object array. The object array being passed to BeginInvoke only has one element, so it matches the parameter count of your callback when it passes that element to it.
|
|
|
|
|
Hi all,
I'm looking for a way to call VS2005 Shared Addin functions from an external VS2005 application.
a) The functions defined in Addin need some special demands?
b) In application how to invoke the function?
Thanks
|
|
|
|
|
|
Hey,
Could someone please point me into the right direction as to what I'd need to use in order to retrieve the size of a file on the web, without downloading the whole thing.
Thanks
|
|
|
|
|
You won't know unless you try to download the thing. There's nothing in the HTTP spec that allows for this.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Try inspecting the ContentLength when you using WebRequest and see if it helps.
|
|
|
|
|
Well I solved my own problem with some help from google.
If anyone was wondering on how you do this - I achieved it with the following code:
WebClient client = new WebClient();
client.OpenRead("http://www.website-here.com/");
string fileSize = client.ResponseHeaders.Get("Content-Length");
That's about it.
|
|
|
|
|
Hi all,
I'm new to C# and currently writing an application for a Windows Mobile 5.0 device using the WebBrowser Control. Now, I'd like my application to process some hyperlinks, instead of the WebBrowser sending a request to the webserver.
There is a possibility to call back a method from within an HTML document (by defining an onclick event in a hyperlink: onclick="window.external.TestMethod('teststring')"). But this does not seem to be supported by WM 5.0 (I can't find the ObjectForScriptingProperty I would have to set, for instance), or am I mistaken?
Is there any alternative way to intercept a click on a hyperlink, some kind of work around? I'm grateful for any kind of help.
Thanks in advance.
Mary
|
|
|
|
|
|
That is excactly what I was looking for. Thanks a lot!
|
|
|
|
|
Does anybody know, how the System.Reflection.Emit.EventBuilder works? How can I define a simple event with it?
|
|
|
|
|
|
I haven't any problem with Emit technology, excepting EventBuilder class.
It's simple to create an "event" as ilasm does (using delegate field, public methods add_* and remove_*)... but it isn't an event(Type.GetEvent(...) returns null)!
EventBuilder perfoms three interesting methods - SetAddOnMethod, SetRemoveOnMethod and SetRaiseMethod.
And... what's the methods body should be? ILasm way? If yes, how can I get a delegate field for EventBuilder based event?
|
|
|
|
|
Hi all,
Are there any controls in C# that can be used as a standard old StringGrid? The DataGrid looks nice and all but it seems to require a DataSource and I'm not using one.
Basically, I just need a way of visually representing a two dimensional string array. OK, maybe not just representing, I need for the user to be able to edit fields in this grid during run time.
Any suggestions?
|
|
|
|