|
In VB.NET you can also have global functions.
Perl combines all the worst aspects of C and Lisp: a billion different sublanguages in one monolithic executable. It combines the power of C with the readability of PostScript. -- Jamie Zawinski
|
|
|
|
|
Hi Guys,
I'm new to socket programming. I need to create a C# program that reads data from multiple servers at the same time or one at a time - whatever is the easiest way.
I have more than a 100 ip address and ports (from the list), If I can't connect and read from the first (IP and port) the program should go to the next IP/PORT from the list and connect and read the data. After that all data retrieved will be saved into the SQL server database.
If you could redirect me to some tutorials or samples it would be of greate help. Or if YOU could help me I would appreciate it very much.
8-( Dabuskol
|
|
|
|
|
There is actually a pretty good simple "chat" example in MSDN. I would recommend downloading it. It also never hurts to get familiar with the System.Net namespace.
|
|
|
|
|
Tom,
Do you have any specific site from MSDN regarding CHAT? I'm sorry but I really need the answer because of the pressure from my boss.
Dabuskol
|
|
|
|
|
In my MSDN Oct 03, in ".Net Samples- How To: Networking" there is a sample simply called "Chat" with documentation and suplemental information. The exact same page is available online at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpqstart/html/cpsmpnetsamples-howtonetworking.asp
I found it simply by doing a search "chat". No divine inspiration...I just knew a chat example existed somewhere.
|
|
|
|
|
Hi Tom,
You're really great with your help.
I've already created a socket program in c# and it was working fine. I just need to trap certain events (errors) while my program is running. Since I have 50(s) or more connections in 1 time I need to monitor which one is not receiving any data for a couple of mins. What I will do is disconnect that particular connection and reconnect again until everything is ok.
Do you suggest any C# Networking Book becuase i'm planning to drop by the bookstore after office so that I'll have a better idea of this matter (first time on networking thing.)
Thanks and more power to you
/dabuskol;
|
|
|
|
|
Hi everyone.
I have been trying to remove a forms captionbar, but without much success. I have tryed setting the FormBorderStyle to None, but that removes the border as well as the Captionbar, but I want to keep the border as the 3D style. Anyone got any idea how this is done without a lot of coding?
Nightcrawler
Resistance is futile - Data (ST:First Contact)
|
|
|
|
|
As far as I know, this cannot be done. This "captionbar" and the border are tied together closely in Windows. However, you could draw the border yourself in an painting event (I guess). That case you must access the Windows (XP) theme, get the border, and draw it on the edge of your form. You must, however, somehow change the client area smaller that it is somehow (because the inside edges of the form are painted to be borders now, not client area). And don't forget to do manual painting for systems that doesn't support themes (anything else that Windows XP systems currently). There are a lot of examples how to use themes so you should have no problems if the main idea works...
|
|
|
|
|
Damn. Well thanks for a quick replay
Resistance is futile - Data (ST:First Contact)
|
|
|
|
|
Hi ppl!
May be you can help me with this:
I have some collection inside collection of my classes and I need to serialize it. The tree looks like this:
class NewsSourceCollection : CollectionBase, ISerializable
{
//This class is a main class and generally will hold all the data and List's
void Add (NewsSourceSingle in_param)
{
this.List.Add(new NewsSourceSingle(in_param));
}
void RemoveAt (int index)
{
this.List.RemoveAt(index);
}
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
//Question number 1: How I can serialize a List from System.Collection ???
}
private newsSourcesColllection(SerializationInfo info, StreamingContext context)
{
//Here goes deserialization
}
} //class close
class NewsSourceSingle : ISerializable
{
//This class will be used by NewsSourceCollection to Add or Remove from List and hold instance of NewsItemsCollection class to add some sub items there
private NewsItemsCollection m_ns;
public NewsSourceSingle ()
{
//c'tor
this.m_ns = new NewsItemsCollection ();
}
void Add(some_param)
{
this.m_s.Add(some_param);
}
.
.
.
.
+same functions to support ISerializable
}
class NewsItemsCollection : CollectionBase, ISerializable
{
//This class will hold all collection of NewsItems
+the same function for supporing ISerializable
}//class close
class NewsItems : ISerializable
{
string pp;
string dd;
+same functions to support ISerializable
} class close
Question number 2: I can Formatter.Serialize (stream,object) but I can not (!) deserialize it !! Why ? Because Assembly of my type 'NewsProg version=1.0.9.245 Token....' is not found !!?????
Question 3: How can I serialize List (of System.Collection) ??
"I have not failed.
I've just found 10,000 ways that won't work."
- Thomas Alva Edison (1847-1931)
|
|
|
|
|
First, read Serializing Objects[^] in the .NET Framework SDK.
If you attribute a class with SerializableAttribute , by default any private and public fields are serialized, so long as those types are serializable. Since you're deriving from the CollectionBase - which uses the ArrayList internally, which is serializable - your class is already serializable. You don't need to implement ISerializable unless you want to override serialization.
The second error is because the Type which is being deserialized is defined in an assembly that cannot be found. Make sure that when deserializing your assembly, your assembly can be found. See How the Runtime Locates Assemblies[^] in the .NET Framework SDK for more information.
For the answer to your third question, see the answers above. Mosts lists in the .NET Framework are already serializable. For example, the following creates an XML document with the content of an ArrayList :
using System;
using System.Collections;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Soap;
public class Test
{
static void Main()
{
ArrayList list = new ArrayList();
list.Add("One");
list.Add("Two");
list.Add("Three");
SoapFormatter formatter = new SoapFormatter();
using (Stream s = new FileStream("Test.xml", FileMode.Create))
formatter.Serialize(s, list);
}
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello,
how can I define ALT+X shortcuts for TabPages. Just inserting a "&" at the right place in the text-property like it works with buttons does not help. I didn't find a property.
thanks in advance
Gigiwig
|
|
|
|
|
I think you have to overriden OnkeyDown event of your form ans set the property of TabControl.SelectedIndex there.
Mazy
"A bank is a place that will lend you money if you can prove that you don't need it." - Bob Hope
|
|
|
|
|
Before that you should set your KeyPreview property of form to true.
Mazy
"A bank is a place that will lend you money if you can prove that you don't need it." - Bob Hope
|
|
|
|
|
I have a Microsoft IntelliMouse Wireless Explorer, which has 3 buttons (left, right and middle) plus 2 other buttons on the side, which normally (by default) act as a back/forward for the web browser, unless otherwise instructed by its options in the Control Panel.
How can I capture these buttons and use them as I wish in my application?
Sammy
"A good friend, is like a good book: the inside is better than the cover..."
|
|
|
|
|
public enum MouseButtons
{
Left = 1048576;
Middle = 4194304;
None = 0;
Right = 2097152;
XButton1 = 8388608;
XButton2 = 16777216;
}
top secret
|
|
|
|
|
Why is that? How else can I assign the Esc shortcut to a menu item?
Sammy
"A good friend, is like a good book: the inside is better than the cover..."
|
|
|
|
|
profoundwhispers wrote:
How else can I assign the Esc shortcut to a menu item?
You can P/Invoke RegisterHotKey , you might also want to include UnregisterHotKey . However why would you want to assign Esc to a menu item, usually when a form is open and someone presses the Esc key it will close the current window.
- Nick Parker My Blog
|
|
|
|
|
Nick Parker wrote:
However why would you want to assign Esc to a menu item
Oh, I hate unstandard windows application like this, you can't do anything with them.
Mazy
"A bank is a place that will lend you money if you can prove that you don't need it." - Bob Hope
|
|
|
|
|
Actually, what I'm trying to do is pretty standard, although it's a workaround. See, when I use the AxWebBrowser control, pressing on Esc to stop the page from loading doesn't seem to work, so I was trying to make it work!
So how can I simply make it work!?
Sammy
"A good friend, is like a good book: the inside is better than the cover..."
|
|
|
|
|
profoundwhispers wrote:
Actually, what I'm trying to do is pretty standard, although it's a workaround. See, when I use the AxWebBrowser control, pressing on Esc to stop the page from loading doesn't seem to work, so I was trying to make it work!
Well, I am not sure what a menu item has to do with what you just said, per your original post. I still think you are going to want to use the RegisterHotKey and probably override the WndProc. Something like the following:
protected override void WndProc(ref Message m)
{
const int WM_HOTKEY = 0x0312;
switch(m.Msg)
{
case WM_HOTKEY:
ProcessHotKey();
}
base.WndProc(ref m);
}
private void ProcessHotKey()
{
}
- Nick Parker My Blog
|
|
|
|
|
The old fashion way: set the MenuItem.Text to "My Caption\tEsc". Notice that you should inserting a tab character between the caption and the shortcut. Don't use the PropertyGrid to do this, since it will escape the backslash (\) as well.
You'll need to handle the escape key yourself, though, by setting Form.KeyPreview to true and overriding the OnKeyDown method in your derived Form class to handle Keys.Escape .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I'm having trouble with getting the display name of my folder via my PIDL. I know the methods work, as they run without error, and everything proceeds almost exactly as expected. However, the STRRET structure that is filled by the GetDisplayNameOf() method gains a pointer in it's union type, however, the type value used to determine what type the STRRET uses, is always set to zero after the method.
mySTRRET = new STRRET();<br />
result = myShellFolder.GetDisplayNameOf(relativePIDL,SHGDN_Flags.SHGDN_NORMAL | SHGDN_Flags.SHGDN_FORPARSING<br />
,ref mySTRRET);
Now, i've managed to pull a string out of the StretToStr method by converting the string to a pointer, and then converting it back to a string once it's been processed - Does anyone know why this works yet my string ref failed to do anything with my string?
myFileName = new string(' ',128);<br />
myFileName += "\0";<br />
<br />
IntPtr myFileNamePointer = Marshal.StringToHGlobalAuto(filePath);<br />
result = COMStuff.StrRetToStr(ref mySTRRET, desktopPIDL, ref myFileNamePointer);<br />
myFileName = Marshal.PtrToStringAuto(myFileNamePointer);
The string I get however, is the full StretToStr file path, so i'm a bit baffled. This probably has something to do with the zero type value. If I manualy set the STRRET value, i get odd results.
Value 1 - Gibberish string of unknown charachters and parenthesis.
Value 2 - "~--*square*" (Square Being the unknown charachter type thing)
Value 3 - null
Can anyone shed any light on this?
Cheers
Cata
|
|
|
|
|
Does anyone have a textbox based control that will only accept valid URLs?
camasmartin
hobby programmer
|
|
|
|
|
Handle the Validating even on a TextBox (or override OnValidating if deriving from TextBox ) and in your validation code, use a Regex instance to check the URL, setting CancelEventArgs.Cancel to true if the regular expression fails.
The regular expression you use is determined by what "URL"s you want to support. The concept of URLs - which is a form of URI - is very vague. Any protocol scheme is allows, though they might not match any protocol handlers. Common schemes are http(s), ftp(s), nntp, news, mailto, gopher, and telnet. Windows adds some (depending on what's installed) like ms-help, its, and some others. You can add them to Mozilla/Netscape, too. And each of these can have slightly different syntax that others don't support.
My advice - unless you want several regular expressions that will slow validation tremendously, just use the Uri class like so:
public class UrlBox : TextBox
{
protected override void OnValidating(CancelEventArgs e)
{
try
{
new Uri(this.Text);
}
catch
{
e.Cancel = true;
}
}
} This should handle most variants of URLs.
Microsoft MVP, Visual C#
My Articles
|
|
|
|