|
Hi,
I have tracked a strange behavior when I close a .NET TCP Socket.
I wrote a TCP-Server which listens on port 6000. I now connect with an self written TCP-Client and everything works fine. When I want to disconnect the client from the server I call code like this:
<br />
public void Disconnect()<br />
{<br />
if (socket.Connected)<br />
socket.Shutdown(SocketShutdown.Both);:~ <br />
socket.Close();<br />
socket = null;<br />
}<br />
When I now run "netstat -a -p tcp" from the commadline I can still see the connection with the state:
localhost:6000 -> localhost:6001 = CLOSING_WAIT (translated from german: SCHLIESSEN_WARTEN)
localhost:6001 -> localhost:6000 = FIN_WAIT_2 (translated from german: FIN_WARTEN_2)
Looks like there are some fragments of the connection still there. By the way... I am not able to create new connection on the same port at this time. Only when I finish my application, the connection between 6000:6001 in "netstat" is gone.
The strange thing is, that if I disconnect with the code below, everything works fine. I cant find any connections with "netstat" after the disconnection, and I'm able to create a new connection with the same ports...
Here is the code:
<br />
public void Disconnect()<br />
{<br />
socket.Close();<br />
socket = null;<br />
}<br />
So... can someone tell me what is happening here? As far as I know it should be right and neccessary to call socket.Shutdown(...) with the TCP-Protocol. I read a lot of MSDN documentation but couldnt find any clues to this. As far as I tracked the problem, it only appears when I call socket.Shutdown(Socketshutdown.Send) . socket.Shutdown(Socketshutdown.Receive) works apperntly fine.
Maybe there is some socket coder outside that can help me.;)
Thanks in advance,
Snow.
|
|
|
|
|
Tooltips for disabled buttons
Sayan
-- modified at 10:28 Sunday 14th May, 2006
|
|
|
|
|
You should at least try to formulate a proper question...
|
|
|
|
|
no
Regards,
mav
--
Black holes are the places where god divided by 0...
|
|
|
|
|
Sayan007 wrote: Tooltips for disabled buttons
Sometimes people make statements rather than ask a question. But, there isn't even a verb in that!
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|
I'm trying to build a little C# program using regular expressions that will filter out the email address and the reason for the mail not reachin the destination.
All that I really want is to extract the email address and the specific reason why the message wasn't sent or recieved.
Example:
Hi. This is the qmail-send program at domain.com.
I'm afraid I wasn't able to deliver your message to the following addresses.
This is a permanent error; I've given up. Sorry it didn't work out.
email address@domain.com:
Sorry, no mailbox here by that name. (#5.1.1)
Thanks in advance for the help.
Regards
Jorge
-- modified at 6:34 Sunday 14th May, 2006
|
|
|
|
|
email\s([^@]+@[^@]+) r|\n|\r\n)+(.*)
This is very basic, but should get the work done.
match[1] is the mail address, match[3] is the reason of the failure.
regards
-- modified 12-Sep-18 21:01pm.
|
|
|
|
|
hello
maybe you can help me to make a comobox to get the values from DB .
and how can I know and save what was picked there.?
thank you
|
|
|
|
|
combobox1.DataSource = ds.Tables[0];
combobox1.TextMember = "<field>"; // I think it's textdatamember, or text, this is the name of the field you want that the user will see
combobox1.ValueDataMember = "<field>"; // this is what you want to know, eg. ID
to get it you do combobox1.Items.SelectedItems - will get the collection of the selected items, and by the indexer you can watch what you want.
|
|
|
|
|
|
Hi i am using VS 2003 , and i want to break at a particular place when a value of object x is changed. IN VB6 we have something called Watchwindows, where we can set a condition when value changes to break
san
|
|
|
|
|
In Visual Studio there is a breakpoints window where you can set conditions for breakpoints.
---
b { font-weight: normal; }
|
|
|
|
|
I'm trying to establish a good way of doing something before finalising my codegen.
Below is an example:
private void Form1_Load(object sender, EventArgs e)
{
Employee emp = ReallyCoolFuncSingle();
}
public Employee ReallyCoolFuncSingle()
{
Employee e = new Employee();
Person p = CoolFuncSingle();
e = (Employee)p;
e.Age = "100";
return e;
}
public Person CoolFuncSingle()
{
Person p = new Person();
p.PersonName="billy bob";
return p;
}
public Person[] CoolFuncArray()
{
Person[] p = new Person[2];
p[0] = new Person();
p[1] = new Person();
p[0].PersonName = "billy bob";
p[1].PersonName = "frank";
return p;
}
public class Person
{
private string _PersonName;
public string PersonName
{
get { return _PersonName; }
set { _PersonName = value; }
}
public static explicit operator Person(Employee e)
{
Person p = new Person();
p.PersonName = e.PersonName;
return p;
}
}
public class Employee
{
#region person stuff
private string _PersonName;
public string PersonName
{
get { return _PersonName; }
set { _PersonName = value; }
}
#endregion
private string _Age;
public string Age
{
get { return _Age; }
set { _Age = value; }
}
public static explicit operator Employee(Person p)
{
Employee e = new Employee();
e.PersonName = p.PersonName;
return e;
}
}
In essence, I'm trying to modify the Person object returned from some functions and return a super class of some sort - whether actually derived or not is not the issue.
It's a wrap and modify type of pattern.
The code above shows a few attempts.
Basically it all works fine for single objects (managed to get around the explicit operator restrictions), but won't work for arrays.
Any ideas?
Cheers,
Simon
> blog:: brokenkeyboards
> what I think of the OPTIONAL keyword in VB.NET? :: here
> CV :: PDF
> skype :: SimonMStewart
|
|
|
|
|
Although I don't have a clue what you want to accomplish with this weird code (why not just let Employee be a subclass of Person?) I'll try to help you:
It won't work for arrays . The problem is that there is no way to defined operators for arrays of a given type. But you can nevertheless transfer its elements one by one to a new array:
Person[] persons = GetMyPersonsArray();
Emplyee[] employess = new Employee[persons.Length];
for (int i = 0; i < persons.Length; i++)
employess[i] = (Employee)persons[i];
-- modified at 4:23 Sunday 14th May, 2006
|
|
|
|
|
Robert Rohde wrote: The problem is that there is no way to defined operators for arrays of a given type.
But others can reference array parameters ie
public static explicit string[] operator (Employee e){}
PS: I allways forget the syntax, could wrong :p
|
|
|
|
|
Yes, but either the return value or the parameter must exactly match the class which is defined in. Thus in your case either return type or parameter type must be Employee and so something like public static explicit Person[] operator (Employee[] e){} is not possible (neither return type nor parameter type is Employee).
|
|
|
|
|
this is the route I want to go.
More like (pseudo code):
public static explicit operator Person[] Employee(Person p)
{
Employee e = new Employee();
e.PersonName = p.PersonName;
return e;
}
So, the Employee object knows how to cast from Person[] to Employee[].
I could go the route of a static function on Employee, but was hoping for something a little more correct.
Cheers,
Simon
> blog:: brokenkeyboards
> what I think of the OPTIONAL keyword in VB.NET? :: here
> CV :: PDF
> skype :: SimonMStewart
|
|
|
|
|
Hi everyone. I just figured this out and I thought I should put it up somewhere in case someone else has spent hours looking for it like I did. Ok maybe not hours...but still. Anyways heres how you can convert a string to any .NET type that can parse a string.
((IConvertible)"1024").ToType(<br />
Type.GetType("System.Int64"),<br />
System.Globalization.CultureInfo.CurrentCulture )<br />
((IConvertible)"5/5/1985").ToType(<br />
Type.GetType("System.DateTime"),<br />
System.Globalization.CultureInfo.CurrentCulture )<br />
((IConvertible)"1024").ToType(<br />
Type.GetType("System.Double"),<br />
System.Globalization.CultureInfo.CurrentCulture )
returns:
1024
5/5/1985
1024.0
I use Type.GetType instead of typeof() because this way we could pass in a string to get type describing what values to convert to. So a potential function could look like this...
object ConvertString(string str_to_convert, string type_to_convert)<br />
{<br />
return ((IConvertible)str_to_convert).ToType(<br />
Type.GetType(type_to_convert),<br />
System.Globalization.CultureInfo.CurrentCulture )<br />
}
|
|
|
|
|
How about using Convert.ChangeType(str_to_convert, Type.GetType(type_to_convert)) ?
|
|
|
|
|
that works
|
|
|
|
|
Hello everyone,
I would like to read an 16-bit signed tif image in my program.
I used GetPixel(x, y) and the pointer method introduced in "Image processing with dummies" but in both case the program give me the message
"OutOfMemoryException".
Could every one help me to read this image or in a ESRI GRID Raster format.
Regards
Isaac
|
|
|
|
|
I would like to develop a scanner software and make it available as freeware for everyone to download and install. The software including the following functions:
1. Scan to File.
2. Scan to Fax.
3. Scan to Email.
4. Photocopy.
5. Others.
I had created a ComboBox. I want the ComboBox to list down all the scanner drivers installed in user's computer, including the TWAIN drivers. Can anybody tell me how to do that?
|
|
|
|
|
How can I search for a USB PNP ID?
For example, when you run "msinfo32.exe" and then expand "Components/USB", it lists all the USB devices as well as their "PNP Device ID".
I tried using This Code[^]; however, it doesn't list my USB device, although it does work properly by detecting the mouse and some other devices.
One thing I noticed is that all the devices that the code above finds start with "HID" in the msinfo32.exe "PNP Device ID"; however, my device starts with USB. My device id is: USB\VID_0403&PID_6001.
-- modified at 20:26 Saturday 13th May, 2006
|
|
|
|
|
I figured it out by using ManagementObjectSearcher class. Wow! This class is really powerful if you ever need to figure out anything from your hardware.
Here is the code:
<br />
string device = "Win32_USBHub";<br />
ManagementObjectSearcher searcher = new ManagementObjectSearcher("Select * from " + device);<br />
foreach(ManagementObject mo in searcher.Get())<br />
{<br />
Trace.WriteLine(mo.GetPropertyValue("Name")+" "+ mo.GetPropertyValue("PNPDeviceID"));<br />
}<br />
Note that there are a ton of hardware classes available from here[^].
Each class has several variables that can be accessed using the GetPropertyValue method.
|
|
|
|
|
So I have this class, AdminPaper and it implements, IComparable to sort an array of AdminPapers by a property of AdminPaper.
The implementation looks like this:
public int CompareTo(object obj)
{
AdminPaper paper = (AdminPaper)obj;
if (this.scoreDouble > paper.scoreDouble)
{
return -1;
}
else if (this.scoreDouble < paper.scoreDouble)
{
return +1;
}
else
return 0;
}
So, this code will sort my array list based upon the scoreDouble field. And this works great, I just call it like this, Array.Sort(papers); , where papers is an un-sorted array of AdminPapers.
However, what if I want to sort papers a different way? Right now I only can sort the way I implemented Icomparable in AdminPapers . Is there a way to have two implementations? How do I do this? Right now the only sorting method I have is the CompareTo method above, is there a way to implement another?
/\ |_ E X E GG
-- modified at 20:48 Saturday 13th May, 2006
|
|
|
|