|
hello everybody in this forum.
i need to ask one question.
i had implemented multicast chat room to connect to multicast enabled ip address and on a specific port.
that's ok......
actually all users will be connected to that chat room who will connect to that ip address with that port pair.
but what if i wanted to create multiple chat rooms .
does that mean i will use multiple ip addresses and multiple ports for creating multiple chat rooms or it is only one ip address and port pair that i will relay on but with additional coding ?????
Human knowledge belongs to the world.
Human knowledge belongs to the world.
|
|
|
|
|
Hello snouto.
Any network program generally falls into two main categories. Either it's client/server app where all clients connect to one server, or it's a peer-to-peer where all apps act as aclient & a server in the same time.
So, whether your program is from the first type or the second (usually chatting programs are from the first type, but you can make p2p chatting program), you use one IP to listen to, but you may liten on different ports using multiple "TCPListener"s for each port. So there will be a listener for each port and each room will have a name and a port. This way Your server may have multiple chatting rooms (each on a different port), and you may add more rooms (or remove) at run time.
If this isn't what you were looking for, or you need more clarification, just ask.
Happy programming.
|
|
|
|
|
I am trying to process some work in the back ground so my UI is not locked up. This is what I have currently:
private void btnPHourly_Click(object sender, EventArgs e)
<code>{
string tempDestination = FileCopier.Properties.Settings.Default.PHourlyPath.ToString();
string tempRemoveable = FileCopier.Properties.Settings.Default.RemoveableDiskPath.ToString();
ValidatePaths(ref tempDestination, ref tempRemoveable);
DisableButtons();
CopyFiles cf = new CopyFiles(tempDestination, tempRemoveable, ExtensionFlag);
EnableButtons();
}</code>
I want to CopyFiles cf = new CopyFiles(tempDestination, tempRemoveable, ExtensionFlag); process to work in the background. How can I implement the BackGroundWorker in this scenerio?
Since I cant pass parameters (such as tempDestination etc) to bgworker I am not sure how I can acomplish this. Can someone up here help me with this issue? Thanks in advance.
|
|
|
|
|
What is "bgworker" and why can't you pass it a string?
"What classes are you using ? You shouldn't call stuff if you have no idea what it does" Christian Graus in the C# forum
led mike
|
|
|
|
|
Well you can pass parameters. The RunWorkerAsync can take an object parameter which will be transferred to the event arguments of the DoWork event callback. You could argue that it is only one parameter and that you need several ones but this is not really a restriction because you can stuff anything you like into that parameter like an ArrayList filled with values, a Hashtable or plain an object array.
using (BackgroundWorker bw = new BackgroundWorker()) {
bw.DoWork += new DoWorkEventHandler(bw_DoWork);
bw.RunWorkerAsync(new object[] { tempDestination, tempRemoveable, ExtensionFlag});
bw.DoWork -= new DoWorkEventHandler(bw_DoWork);
}
private void bw_DoWork(object sender, DoWorkEventArgs e)
{
object[] o = (object[])e.Argument
CopyFiles cf = new CopyFiles((string)o[0], (string)o[1], (string)o[2]);
}
Not tested but should work
|
|
|
|
|
hi
i'm making a form in VS.Net .When i debug the code,i want my textbox come with grids.
But i dont know how i drawing grids to the textbox and show it when the form run.That is in one way,i want to use InitializeComponent() method.
how can i do it
thanks
|
|
|
|
|
You cannot use grid in textbox. Use DataGrid instead.
It is simple to use datagrid. Just put datagrid in your
form. Then fill datagrid using datatable.
e.g. :
DataTable dataTable = new DataTable();
dataTable.Columns.Add(new DataColumn("X", typeof(int));
dataTable.Columns.Add(new DataColumn("Y", typeof(int));
for(int i = 0; i < 10; i++)
{
DataRow dataRow = dataTable.NewRow();
dataRow["X"] = i;
dataRow["Y"] = i;
dataTable.Rows.Add(dataRow);
}
this.dataGrid1.DataSource = dataTable; Now you can see a table with X and Y column, fill with number 0 until 10.
|
|
|
|
|
i will study about this , thank you very much stancrm;)
|
|
|
|
|
If I've got a WeakReference:
private WeakReferences weakRef = new WeakReference();
...
weakRef.Target = new string[...];
Am I guaranteed the following will always work?
if(weakRef.IsAlive)
{
string[] args = (string[])weakRef.Target;
}
Isn't it possible that the garbage collector will kick in right after the IsAlive check, thus collecting the object before I can get the Target?
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Islamic Domination: Coming to a Jewish state near you!
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
|
|
Use the IsAlive method if you only want to check the status of the reference. If you actually want to use the reference there is no reason to use IsAlive first, just get the value from the Target property and check if it's null.
---
b { font-weight: normal; }
|
|
|
|
|
Hello, i would like to know how to sort an xml file. here is the xml file i have:
<?xml version='1.0'?>
<Books>
<Book>
<Title>Advanced XML</Title>
<Publisher>Lucerne Publishing</Publisher>
</Book>
<Book>
<Title>Learn XML Today</Title>
<Publisher>MSPress</Publisher>
</Book>
<Book>
<Title>XML for Gurus</Title>
<Publisher>Lucerne Publishing</Publisher>
</Book>
<Book>
<Title>Developing XML solutions</Title>
<Publisher>MSPress</Publisher>
</Book>
</Books>
I don't have any template or style file.
I want to display a sorted information inside a listbox in C#:
Advanced XML, Lucerne Publishing
XML for Gurus, Lucerne Publishing
Developing XML solutions, MSPress
Learn XML Today, MSPress
I assume that we want to sort by the publisher first and then by the title.
Any suggestion will be great.
Donkaiser
|
|
|
|
|
private static void SortXmlTest()
{
string data = @"<?xml version='1.0'?>
<Books>
<Book>
<Title>Advanced XML</Title>
<Publisher>Lucerne Publishing</Publisher>
</Book>
<Book>
<Title>Learn XML Today</Title>
<Publisher>MSPress</Publisher>
</Book>
<Book>
<Title>XML for Gurus</Title>
<Publisher>Lucerne Publishing</Publisher>
</Book>
<Book>
<Title>Developing XML solutions</Title>
<Publisher>MSPress</Publisher>
</Book>
</Books>";
XmlDocument doc = new XmlDocument();
doc.LoadXml(data);
ArrayList books = new ArrayList();
foreach (XmlElement book in doc.DocumentElement.ChildNodes)
books.Add(book);
books.Sort(new BookComparer());
doc.DocumentElement.RemoveAll();
foreach (XmlElement book in books)
doc.DocumentElement.AppendChild(book);
doc.Save(Console.Out);
}
class BookComparer : IComparer
{
public int Compare(object x, object y)
{
//return (x as XmlElement)["Title"].InnerText.CompareTo((y as XmlElement)["Title"].InnerText);
int publisherCompare = (x as XmlElement)["Publisher"].InnerText.CompareTo((y as XmlElement)["Publisher"].InnerText);
if (publisherCompare != 0)
return publisherCompare;
return (x as XmlElement)["Title"].InnerText.CompareTo((y as XmlElement)["Title"].InnerText);
}
}
I hope I didn't just do all your homework.
|
|
|
|
|
Hi Reinux,
Thank you for your help. im still new to XML programming.
I was compiling ur code and it gave me this error in vs 2005:
"Using the generic type 'System.Collections.Generic.IComparer<t>' requires '1' type arguments"
I've been looking around and i didn't see any implementation of the parameter.
Thx again
Donkaiser
|
|
|
|
|
Ah, that was actually .NET 1.1 code. You can still make it work by adding
"using System.Collections" to the top of your code, but here's the .NET 2.0 version (you don't need BookComparer):
private static void SortXmlTest()
{
string data = @"<?xml version='1.0'?>
<Books>
<Book>
<Title>Advanced XML</Title>
<Publisher>Lucerne Publishing</Publisher>
</Book>
<Book>
<Title>Learn XML Today</Title>
<Publisher>MSPress</Publisher>
</Book>
<Book>
<Title>XML for Gurus</Title>
<Publisher>Lucerne Publishing</Publisher>
</Book>
<Book>
<Title>Developing XML solutions</Title>
<Publisher>MSPress</Publisher>
</Book>
</Books>";
//Create a new document and load the sample data.
XmlDocument doc = new XmlDocument();
doc.LoadXml(data);
//Copy all of the Book elements to a list.
List<XmlElement> books = new List<XmlElement>();
foreach (XmlElement book in doc.DocumentElement.ChildNodes)
books.Add(book);
//Sort the data -- if the publishers are the same, sort by title.
books.Sort(delegate(XmlElement x, XmlElement y)
{
int publisherCompare = x["Publisher"].InnerText.CompareTo(y["Publisher"].InnerText);
if (publisherCompare != 0)
return publisherCompare;
return x["Title"].InnerText.CompareTo(y["Title"].InnerText);
});
//Remove all the Book elements from the document, and put the sorted copy back in.
doc.DocumentElement.RemoveAll();
foreach (XmlElement book in books)
doc.DocumentElement.AppendChild(book);
//Print the data to the console.
doc.Save(Console.Out);
}
|
|
|
|
|
uraaa! I got it working and listed on a textbox. If i listed only the titles of the books in the listbox. when i select an item an click an "ok button". How can a retrieve the matching publisher?
Thanks a lot again
Donkaiser
|
|
|
|
|
Practically every control in Windows Forms has a handy Tag property that you can assign what ever you want to.
So you can assign those book XmlElement items that you extracted earlier to each one of their corresponding list items.
And then when you click an ok button, check the listbox.SelectedItem.Tag property -- that'll be whatever you assigned to the tag.
Edit: sorry, that's ListView I'm thinking of.
ListBox lets you assign any type of object, so you can make a custom class and override the ToString method to have it show the right text in the list box.
So make a class like this:
class Book
{
public Book(string name, string publisher)
{
this.name = name;
this.publisher = publisher;
}
string name, publisher;
public string Publisher
{
get { return publisher; }
}
public string Name
{
get { return name; }
}
public override string ToString()
{
//Just show the name
return name;
}
}
When you add an item to the list box, do something like this:
listBox.Add(new Book(element["Name"], element["Publisher"]);
When you want to get the publisher for the selected book, do this:
publisher = (listBox.SelectedItem as Book).Publisher;
-- modified at 19:59 Friday 19th May, 2006
|
|
|
|
|
I am writing some code in C# and have the need to call a third party java api. I am attempting to write a C++ dll that can be called from
C# -> C++ -> Java -> Java API.
Everytime I make a call to JNI_CreateJavaVM from Java I get a JNI_ERR or -1
I do have a java class file in the same directory.
I also have the location of jvm.dll in the system path variable.
Also, if I run the C++ code as a stand-alone executable instead of a DLL it works.
Any Help would be appreciated.
Thanks
JNIEnv *env;
JavaVM *jvm;
jint res;
JavaVMInitArgs vm_args;
avaVMOption options[1];
options[0].optionString = "-Djava.class.path=C: \\CsstProductInterface.jar";
vm_args.version = JNI_VERSION_1_2;
vm_args.options = options;
vm_args.nOptions = 1;
vm_args.ignoreUnrecognized = JNI_TRUE;
res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
if(res < 0)
{
AddToLog("UNABLE to start JVM\n\n");
}
Pat
|
|
|
|
|
I have a piece of code in which collection is assigned to dropdown list's data source property for binding data. When multiple clients access the site simultaniously the following exception was being thrown:"Collection was modified; Enumeration Operation may not execute". Any idea about y this is happening and how to get this code work???
|
|
|
|
|
Is not allowed to modify any item of a collection in any way while you're inside the foreach loop on that collection.
You may try to lock the piece of code, something like the following
lock(this) {
...
}
paco
|
|
|
|
|
Thank you carlopagliei for the reply; but i am not using the foreach statement. I have a code like
ddlTest.DataSource= TestCollection;
ddlTest.DataBind();
Otherthan populating the collection from database, i am not manipulating the collection.
|
|
|
|
|
It was only an example. You don't use foreach but probably the problem is that while DataBind() method enumerates over the TestCollection another piece of code (maybe the same but from another thread) is doing the same. So try to lock the code that acess TestCollection before use it:
lock (TestCollection) {
ddlTest.DataSource= TestCollection;
ddlTest.DataBind();
}
paco
|
|
|
|
|
Hi.
when we create a class, and in code type 'ClassName.', some methods and properties appear, and on an object of that class there is another properties and methods.
first : we don't write them for that class, these properties and methods come from where?
second : for class and object these are difference, why?(Is it for static methods and properties?)
Best wishes
|
|
|
|
|
mehrdadc48 wrote: first : we don't write them for that class, these properties and methods come from where?
Are you referring to methods such as ToString()? They would be inherited from the base class (in this case, System.Object).
mehrdadc48 wrote: second : for class and object these are difference, why?(Is it for static methods and properties?)
You are correct. You cannot call static methods using an object instance.
Cheers,
Vikram.
I don't know and you don't either.
Militant Agnostic
|
|
|
|