|
so If I'm doing a BeginReceive on my client socket....can I just to a regular send for sending data or do I need to do a BeginSend to make my client socket app truly async?
Also if I want to fire an event when data comes in ...and I want to pass the incoming data with my event....do I want to do that after I call my EndReceive?
Thanks
Tom Wright
tawright915@gmail.com
|
|
|
|
|
For firing the event when data comes in, you'll have to do that after you call EndReceive, or you won't know how much data you received (and possibly your buffer will not have the data - can't remember off-hand).
I've always used regular sends for sending data, and BeginReceive/EndReceive on the receiving end. I don't know if this really makes async, but I never quite understood the reasons for the overhead involved with BeginSend/EndSend - regular Send has always worked just fine for me.
-----
In the land of the blind, the one eyed man is king.
|
|
|
|
|
Do I need to block on my send when sending?
Tom Wright
tawright915@gmail.com
|
|
|
|
|
Hello
Tom Wright wrote: I need to do a BeginSend to make my client socket app truly async?
Sending and receiving are two different operations. If you send using Send() method and recieve using BeginReceive() method, then your sending will be blocking, or sync opertation while recieving is not!!
For me, I prefer using multithreading. This is what really happens in the background. The Begin methods actually make a thread for you to do the job. Well, I like to have a control over my threads, even if I have ot write few more lines!!
So, my advice, Make a thread for each socket to handle sending/receiving data. A better more advanced approach -needs more care though- is to make two threads for each socket. One to send and the other to receive.
Regards
|
|
|
|
|
The problem is (I have this now) that when doing seperate threads for send and receive, I cannot seem to get the correct status of the socket back. So if the connection drops....ungracefully. My app never knows and keeps trying to send. So one way to get around this is to use the BeginSend and BeginReceive.
Do you have any other suggestions? Thank
Tom Wright
tawright915@gmail.com
|
|
|
|
|
Hello
Sure!! There are plenty. You may check the status of the connection using the Connected property, or even set a timeout of the send operation using the SendTimeOut property to a reasonable value.
Regards
|
|
|
|
|
been there done that....If I send data...it sends it,not sure to where and the connected property only return the status of the connection from the last io on the port.
I've tried poll and ...one other method that escapes me.
Thanks
Tom Wright
tawright915@gmail.com
|
|
|
|
|
Hello
Quoted from MSDN:
If you need to determine the current state of the connection, make a nonblocking, zero-byte Send call. If the call returns successfully or throws a WAEWOULDBLOCK error code (10035), then the socket is still connected; otherwise, the socket is no longer connected.
Try to use this non-blocking BeginSend() call just to check the current status.
I hope this helps.
Regards
|
|
|
|
|
Greetings again!
I have a question concearning delegates:
How to use a delegate which is passed by another class.
Here the exemple code, which shoould explain my question:
<br />
delegate void dSendParameters(string para);<br />
and in the Method
<br />
dSendParameters dSend = delegate(string para) { };<br />
Classes.OtherClass otherclass = new Classes.OtherClass(dSend);<br />
and her the code in the other class, which should "catch" the delegate
<br />
public class OtherClass<br />
{<br />
public OtherClass(Delegate dSend)<br />
{<br />
}<br />
<br />
private void buttonClickme_Click(object sender, EventArgs e)<br />
{<br />
}<br />
}<br />
With Parameters it´s easy, just pass a ref and create a Parameter which get´s the value of the ref Parameter. But how to make a delegate available this way??
I need this, because I need to make referenced Assemblies able to call Methods of the
executing Assembly.
Thanks in advance,
ezazazel
|
|
|
|
|
Your code can benefit from a better approach at the problem but I will give you a simple solution
public class Foo{
public delegate void dSendParameters(string para);
public event SendParameters;
protected virtual OnSendParameters(parm list){
if(SendParameters != null){
SendParameters(someString);
}
}
private void buttonClickMe_Click(object sender, EventArgs e){
OnSendParameters(someparams);
}
}
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 rightly to apprehend the kind of confusion of ideas that could provoke such a question. - Charles Babbage
|
|
|
|
|
Thx for your sample code.
One more question if I may:
how to make the delegate from the exe to the delegate in your foo class
<br />
public delegate void dSendParameters(string para); <br />
public event EventHandler SendParameters;<br />
public OtherClass(Delegate dSend)<br />
{<br />
<br />
}<br />
Or did I missunderstand your code? If so, I´m sorry.
Thx in advance
-- modified at 16:00 Thursday 24th August, 2006
|
|
|
|
|
This maybe? I don't really understand the question.
public class SomeOtherCode{
public void SampleMethod(){
Foo foo = new Foo();
foo.SendParameters += new dSendParameters(SomeMethod);
}
public void SomeMethod(string param){
...
}
}
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 rightly to apprehend the kind of confusion of ideas that could provoke such a question. - Charles Babbage
|
|
|
|
|
I mean this:
public delegate void dSendParameters(string para);
public event SendParameters;
public OtherClass(Delegate dSend)
{
//this.SendParameters += dSend;
//or
//dSendParameters += dSend
}
which doesnt´t work
What I want is:
Assembly a (executable), Assembly b(dll)
b is referenced in a
a has a method which needs to be called by b
so I send a delegate to be when I call the class
the sent delegate is invoked inside b
Thx
|
|
|
|
|
public delegate double DFunction(double d);
public double Sin(double d){
return Math.Sin(d);
}
public double PerformAction(DFunction d){
double e = d(5d);
return e;
}
private void button1_Click(object sender, EventArgs e) {
PerformAction(new DFunction(Sin));
}
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 rightly to apprehend the kind of confusion of ideas that could provoke such a question. - Charles Babbage
|
|
|
|
|
You can hold the delegate as a field like any other object:
public class OtherClass {
private dSendParameters _dSend;
public OtherClass(dSendParameters dSend) {
_dSend = dSend;
}
public void SomeOtherMethodCallingDSend() {
_dSend("SomeParam");
}
}
|
|
|
|
|
public class OtherClass <br />
{<br />
Delegate _dSend;<br />
public OtherClass(Delegate dSend)<br />
{<br />
_dSend = dSend; <br />
}
works!!
Thanks Robert for your suggestion. Can now send and catch delegates in every direction.
|
|
|
|
|
What I want to do is say
"Only Add classes that implement interfaceA or interfaceB"
so saying
public List<T> where T: interfaceA, interfaceB {}
but that says they must implement both interface A and B.
How can I say A or B?
--------------------------------------------------------
1 line of code equals many bugs. So don't write any!!
My mad coder blog
|
|
|
|
|
You can't. Probably the best option would be to use a factory method or a singleton, with a derived class for each interface. This is the same method used by the Comparer<T>.Default property.
For example:
public abstract class MyClass<T>
{
private static readonly MyClass<T> _instance = CreateInstance();
public static MyClass<T> Instance
{
get { return _instance; }
}
private static MyClass<T> CreateInstance()
{
Type itemType = typeof(T);
Type resultType = null;
if (typeof(InterfaceA).IsAssignableFrom(itemType))
{
resultType = typeof(<span>MyClassA<></span>).MakeGenericType(itemType);
}
else if (typeof(InterfaceB).IsAssignableFrom(itemType))
{
resultType = typeof(<span>MyClassB<></span>).MakeGenericType(itemType);
}
if (null == resultType) throw new ArgumentException("Type parameter \"T\" must implement InterfaceA or InterfaceB.");
return (<span>MyClass<T></span>)Activator.CreateInstance(resultType);
}
}
internal sealed class MyClassA<T> : MyClass<T> where T : InterfaceA
{
...
}
internal sealed class MyClassB<T> : MyClass<T> where T : InterfaceB
{
...
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|
|
That both A and B implement then you can check for it instead.
public interface IShape;
public interface IEvenPolygon : IShape;
public interface IOddPolygon : IShape;
public List<t> where T: IShape;
The problem is what you want isn't type safe.
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 rightly to apprehend the kind of confusion of ideas that could provoke such a question. - Charles Babbage
|
|
|
|
|
Do you have the source code to interfaceA and interfaceB? If so:
interface IAmDaddy
{
}
interface interfaceA : IAmDaddy
{
}
interface interfaceB : IAmDaddy
{
}
public List<T> where T : IAmDaddy
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Dumbest. Movie. Title. Evaaar.
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Hi
could any one show me the best way to extract the info i need from the file below. Basicly the files are hand historys from a poker site and i would like to keep track of how often a player calls checks folds and so on. The file is in html (hoping it posts ok) , or if any one could tell me if it would be better to convert the file to xml (if possible) and extract the data that way?
well here is a short part of the file .....
Real Money Ring Game | Table Name | Hand ID | Game | Stakes | Casanova | 10474702-12327 | Holdem Limit | $0.25/$0.50 | [Jul 31 16:03:20] : Hand Start. | [Jul 31 16:03:20] : Seat 1 : davebass has $31.99 | [Jul 31 16:03:20] : Seat 2 : PoKaBoT has $15.21 | [Jul 31 16:03:20] : Seat 4 : WC2006 has $9.82 | [Jul 31 16:03:20] : Seat 6 : xbambamx has $8.02 | [Jul 31 16:03:20] : Seat 8 : drurylane has $23.05 | [Jul 31 16:03:20] : Seat 9 : modeselect has $3.34 | [Jul 31 16:03:20] : xbambamx is the dealer. | [Jul 31 16:03:21] : drurylane posted small blind. | [Jul 31 16:03:21] : modeselect posted big blind. | [Jul 31 16:03:21] : Game [12327] started with 6 players. | [Jul 31 16:03:21] : Dealing Hole Cards. | [Jul 31 16:03:21] : Seat 2 : PoKaBoT has 5s Ts | [Jul 31 16:03:25] : davebass folded. | [Jul 31 16:03:26] : PoKaBoT folded. | [Jul 31 16:03:29] : WC2006 called $0.25 | [Jul 31 16:03:32] : xbambamx folded. | [Jul 31 16:03:34] : drurylane called $0.13 | [Jul 31 16:03:35] : modeselect checked. | [Jul 31 16:03:36] : Dealing flop. | [Jul 31 16:03:36] : Board cards [As Kc 4d] | [Jul 31 16:03:38] : drurylane checked. | [Jul 31 16:03:38] : modeselect checked. | [Jul 31 16:03:42] : WC2006 checked. | [Jul 31 16:03:42] : Dealing turn. | [Jul 31 16:03:42] : Board cards [As Kc 4d 8s] | [Jul 31 16:03:45] : drurylane bet $0.50 | [Jul 31 16:03:45] : modeselect folded. | [Jul 31 16:03:52] : WC2006 called $0.50 and raised $0.50 | [Jul 31 16:03:53] : drurylane called $0.50 | [Jul 31 16:03:53] : Dealing river. | [Jul 31 16:03:53] : Board cards [As Kc 4d 8s Js] | [Jul 31 16:03:56] : drurylane checked. | [Jul 31 16:03:57] : WC2006 bet $0.50 | [Jul 31 16:03:58] : drurylane called $0.50 | [Jul 31 16:03:58] : Showdown! | [Jul 31 16:04:00] : Seat 4 : WC2006 has 8d Ac | [Jul 31 16:04:00] : WC2006 has Two Pair: Aces and 8s | [Jul 31 16:04:01] : WC2006 wins $3.57 with Two Pair: Aces and 8s | [Jul 31 16:04:10] : Hand is over. |
Table of contents |
if i havent been very clear or this file has posted terribly and you would like to help i could always email a file to you to take a look @ ... many thanx
The top part of the file which looks extreemly messy in the post is not all that important its just the hand numbers , the main part is where you can see "Hand Start" .
|
|
|
|
|
Have you tried opening this up with an XML parser? It looks well-formed enough that you could do that. In this case, you could use an XmlDocument object and start grabbing data out of it.
Logifusion[^]
If not entertaining, write your Congressman.
|
|
|
|
|
Hi,
Use Regex to search for specific patterns.
<br />
"(\\w+)\\s*=\\s*"<br />
"\"\\s*(.*?)\\s*\""
These will match all the attributes in the html like name = "value"
Try forming the proper regex for your situation.
<marquee>"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
Anant Y. Kulkarni
|
|
|
|
|
Hi
When I'm trying to Add something to my ListvView (multiple columns), I receive this strange error in debug mode:
A first chance exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll
The code (*):
lstProps.Items.Add(new ListViewItem(new string[] {"one", "two" }));
Which resides in private void receivedIt(RemovableStorage r, EventArgs e) .
The strange thing is that the same code (*) does work in the Form_Load method, or some Botton_Click method! Am I doing something totally wrong?
I am searching for 2 days now and all the online samples are doing the same - and I'm getting a bit of dissapointed in the ListView control Hopefully someone can help me?
Thanks a lot!
|
|
|
|
|
You are probably trying to access the ListView control from a non-UI thread. You can use the InvokeRequired property to determine whether you are on the UI thread, and the Invoke method to transfer execution to the UI thread.
For example:
private delegate void ReceivedItDelegate(RemovableStorage e, EventArgs e);
private void receivedIt(RemovableStorage r, EventArgs e)
{
if (this.InvokeRequired)
{
this.Invoke(
new ReceivedItDelegate(receivedIt),
new object[2] { r, e });
}
else
{
lstProps.Items.Add(...);
...
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|