|
You need to add a ListBox control to your form. listBox1 will then refer to that control, and add whatever you call the Add method with as arguments. Be careful though; it will add the items, but displays the ToString representation of them. If it's your own class, override the method to provide your own implementation of ToString
|
|
|
|
|
Hi,
I have a form1.cs which has a listBox control...
I have defined the server class in another file using(File->
New->File option)but in the same project...So im not able to
use listBox1.Items.Add()...
If i do so it gives me an error
|
|
|
|
|
Use the server class in the usual way. When you get told that you have received a message, add it to the listbox
|
|
|
|
|
 Hi,
This is the server code:
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
public class UdpServer
{
public static void Main()
{
try
{
int recv;
byte[] data = new byte[1024];
IPEndPoint ipep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9050);
Socket newsock = new Socket(AddressFamily.InterNetwork,SocketType.Dgram, ProtocolType.Udp);
newsock.Bind(ipep);
Console.WriteLine("Waiting for a client...");
IPEndPoint sender = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9050);
EndPoint tmpRemote = (EndPoint)(sender);
recv = newsock.ReceiveFrom(data, ref tmpRemote);
Console.WriteLine("Message received from {0}:", tmpRemote.ToString());
Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv));
string wel = "Welcome to my test server";
data = Encoding.ASCII.GetBytes(wel);
newsock.SendTo(data, data.Length, SocketFlags.None, tmpRemote);
listBox1.Items.Add(data);
ASCIIEncoding asen = new ASCIIEncoding();
newsock.Send(asen.GetBytes("The string was recieved by the server."));
Console.WriteLine("\nSent Acknowledgement");
listBox1.Items.Add("The string was recieved by the server.");
newsock.Close();
}
catch(Exception e)
{
Console.WriteLine("Error..... " + e.StackTrace);
}}}
This is Form1.cs where i have called the client
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Windows.Forms;
namespace WindowsApplication13
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Callback();
}
private void Callback()
{
try
{
byte[] data = new byte[1024];
listBox1.Items.Add("Connecting....");
IPEndPoint ipep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9050);
Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
listBox1.Items.Add("Connected");
data = Encoding.ASCII.GetBytes("welcome");
listBox1.Items.Add("Transmitting...");
server.SendTo(data, data.Length, SocketFlags.None, ipep);
IPEndPoint sender = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9050);
EndPoint tmpRemote = (EndPoint)sender;
int recv = server.ReceiveFrom(data, ref tmpRemote);
listBox1.Items.Add( tmpRemote.ToString());
listBox1.Items.Add(Encoding.ASCII.GetString(data, 0, recv));
listBox1.Items.Add("Stopping client");
server.Close();
}
catch (Exception e)
{
Console.WriteLine("Error..... " + e.StackTrace);
}}}}
I have sent a string Welcome to the server and this works well
The following lines are displayed in the list box control
But the other listBox1.Items.Add()does not work..
What changes should i make to display
listBox1.Items.Add("Connecting....");
listBox1.Items.Add("Connected");
listBox1.Items.Add("Transmitting...");
|
|
|
|
|
 Hi,
I have made some changes to the above code and i have made the client and the server to communicate...
Now i need to perform a small check...
i have sent a string hello from the client to server...
the string is received in the server...Once it is received i want to check whether the received string is right...if it is right it must send another message to the client...So i used a" if" loop....When i use this loop im not able to receive the message from the server...
Please tell me the changes
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
public class UdpServer
{
public static void Main()
{
try
{
int recv;
byte[] data = new byte[1024];
IPEndPoint ipep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9050);
Socket newsock = new Socket(AddressFamily.InterNetwork,SocketType.Dgram, ProtocolType.Udp);
newsock.Bind(ipep);
Console.WriteLine("Waiting for a client...");
IPEndPoint sender = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9050);
EndPoint tmpRemote = (EndPoint)(sender);
recv = newsock.ReceiveFrom(data, ref tmpRemote);
Console.WriteLine("Message received from {0}:", tmpRemote.ToString());
Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv));
if (Encoding.ASCII.GetString(data)=="hello")
{
data = new byte[1024];
string ss = "Welcome to the Server";
data = Encoding.ASCII.GetBytes(ss);
newsock.SendTo(data, data.Length, SocketFlags.None, tmpRemote);
}
Console.WriteLine("\nSent Acknowledgement");
newsock.Close();
}
catch(Exception e)
{
Console.WriteLine("Error..... " + e.StackTrace);
}
}
}
|
|
|
|
|
Hi Evryone
How can I copy Form (Code + designing) in project and change his Name ?
(I work on WinCE)
thank's for any help
|
|
|
|
|
right click on the Form you want to copy then select "Copy". Now, select the project you want to copy the form to, then right click and select "Paste"
Once the Form is copied, make sure it is selected then right click and select "Rename". This will only rename the file, not the class. you will need to change your class name manually.
Yusuf
|
|
|
|
|
Thank's for the help
But what whit the Code ?
I need the code, I need that all the function of the Form will work too
|
|
|
|
|
what code? Didn't you ask to copy Form+Code?
Yusuf
|
|
|
|
|
One way to do this is to select your form in Solution Explorer, then from the File menu select Save <your form name here> AS... and save it with the new name. Then right click on the project in Solution Explorer and select Add | Existing Item... , navigate to the old form and select it.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I've got a program I've written that uses an Access Database for a backend. I've been using it on XP for awhile now with no issues. However recently I've got a new user who has Vista 64 bit. My application crashes before it even finishes loading. Using some debug code in a custom compile I did for him I've narrowed it down to the following section of code:
string sAppPath = (System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)).Replace("file:\\", "");
public System.Data.OleDb.OleDbConnection DBConnection = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + (sAppPath + "\\Database.mdb"));
sSQLStatement = ("SELECT Filename FROM Scriptures");
System.Data.OleDb.OleDbCommand SQLCommand = new System.Data.OleDb.OleDbCommand(sSQLStatement, DBConnection);
try
{
if (DBConnection.State.ToString() == "Closed") DBConnection.Open();
System.Data.OleDb.OleDbDataReader DataReader = SQLCommand.ExecuteReader();
while (DataReader.Read())
{
}
DataReader.Close();
DBConnection.Close();
}
The program crashes on this line:
if (DBConnection.State.ToString() == "Closed") DBConnection.Open();
I'm at a loss as to why this would work on XP but not Vista. I don't have a Vista machine readily available for testing at this time.
Any help would be greatly appreciated. Thanks!
|
|
|
|
|
First off, you really need to get yourself a good C# book and do some reading, because you have some serious fundamental flaws in your code. The Database connection State is an Enumerated type (see example usage[^]), you need not cast it to a String and then compare, you should be comparing the Enumerated types. Additionally, you should really make use of Using[^] statements in your code, it will make for cleaner code, and will ensure the objects are probably closed and disposed.
I see one potential problem, in that you're creating an instance of a SQLCommand using a connection object that might be null; and to top it off, you're doing that outside the scope of your Try/Catch block.
See this line: System.Data.OleDb.OleDbCommand SQLCommand = new System.Data.OleDb.OleDbCommand(sSQLStatement, DBConnection);
If you're not sure if the connection has been created and opened, then you should do that first. Once you have a valid connection, THEN create your SQL Command and hook that up to the connection and execute your query (see Example[^] on MSDN)
But seriously, go read about Enumerated types and Using statements, and hopefully this will help you over come your problem.
Last modified: 13mins after originally posted --
|
|
|
|
|
From what I know there are no 64 bit ODBC drivers for MS Access
|
|
|
|
|
It the application is specifically targeted to x86, it should default to use the 32-bit driver.
|
|
|
|
|
Hello,
i'm writing a malware detection system, and i want to find a way to monitor downloaded files, i could use FileSystemWatcher but i need to find possible malicious hosts to possibly block them using my firewall, any ideas on that? i've already written code for the database files and the comparision algorithms
i also have some experience in the task i need, i've done a project using C last year to monitor tcp packets for syn flood patterns,though this time the packet is not enough, i need to compare the full downloaded file
Thank you.
|
|
|
|
|
you need to implement the snifer ,you should capture the packet and analyze that if this packet is transfering any file then if yes then you enable your firewall
|
|
|
|
|
analyzing a single packet at a time will trigger loads of false alarms, i need to scan a file once it's downloaded, but still, if i use this how will i know that a file is being downloaded? and where to?
|
|
|
|
|
Hi,
I am able to open and display an Excel sheet but I would like to locate some headers by name.
Thanks
|
|
|
|
|
Are you using Microsoft.Office.Interop.Excel ?
Calin
|
|
|
|
|
Hello Calin, I am using Microsoft.Office.Interop.Excel but I don't know how to parse the header row to look for specific words, like, Power, Failure Rate etc.
Any help would be greatly appreciated.
alvas89
|
|
|
|
|
You could use the interop assemblies, which requires Office to be installed, or you could use an approach similar to this[^], which accesses the spreadsheet using a connection string in much the same way as a database. You can then access the individual sheets, rows, columns and cells
|
|
|
|
|
Hello Computafreak, I use the interop but I don't know how to read one or two specific header that include some leywords like Power or Failure rate etc. Being able to read all the rows hasn't helped me so far. I need a more specific info.
Thanks for your suggestions,
alvas89
|
|
|
|
|
hi
i want to execute a file in a CD image (iso, nrg, ...)
image format is not matter!
i want to convert several file of a software to a single file (image) and write an extra program in C# that run the program in image! so others can not see my software components!
plz help me if you can wrap software components(dll,image,audio,...) in anyway that anyone can not see thats component easyly when use the software.
Additional expand
i am writing a game, i dont want to anyone can grab my game image & audio & ... but my game engine can not support encryption! so i want to wrap my game with all its resource!
modified on Sunday, March 1, 2009 4:36 PM
|
|
|
|
|
Making it a common CD image format seems like a bad way to protect anything.
Why are you worried about users seeing the components anyway? If they want to use it, they don't want to break it.. (and even if they do, it's their problem)
An easy way to "hide" the components would be to zip them together and give it an other extension (say, .dat), regular users wouldn't mess with it and that sounds precisely like what you want. You could use #ZipLib[^] for this, it's free (and the license is friendly).
|
|
|
|
|
See Harolds response.
Also google for '.NET obfuscator'. Obfuscators mess with the code, don't worry it still runs, in a way that makes it difficult for others to read. Which is sort of what you want to achieve.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|