|
|
Comments and Discussions
|
|
 |

|
Is it possible start a initial message loop from server to client (server -> client -> server) ?
|
|
|
|

|
Excellent explanation great work..
|
|
|
|

|
I'm under company restriction to use VB only (and I prefer it anyway). I've updated a copy of the source to include a VB version of the server code. Anyone know if there is a way I can upload that here? Hate to have someone else have to go through the same effort.
|
|
|
|

|
Hi Stan,
Your article is very nicely explained. However, You have used
listenSocket = new Socket(this.socketListenerSettings.LocalEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
in Your SocketListener.cs file. Which means that Socket is using Tcp protocol. Now when I am reading the documentation at [^]
Please see the Quote: Reliability: section. It says that Quote: assigning a sequence number to each octet
transmitted . The Question is Do we really need to pass sequence number explicitly?
Thanks
Shankbond
|
|
|
|

|
Hi
Excellent Article.Can you tell me how we can send Data-Table or data from database from server to client in asynchronous socket programming in c#. Any idea,reference or code.
Thanks in Advance
|
|
|
|

|
Admitting that it took me some evenings to understand all, but thats is the first socket example which seems to guide one into a direction which leads to production quality code.
Great Job!
|
|
|
|

|
in your project,in class SocketListenerSettings you left a field called receivePrefixLength.
someone can set a value as any Int32,but in class SocketListener,you get a prefixLen with BitConverter.ToInt32() method,this is to say,no mather what the receivePrefixLength is,you always
use only the first four bytes,this will probably cause a bug if the value is not 4.
the same as sendPrefixLength ,maybe.
|
|
|
|
|

|
I see this has been touched upon already and so has a suggestion for threading the XAsync methods. Though this application may handle large volume connections successfully, it appears to accomplish this in a LIFO process. In the event that (n) number of connections attempt simultaneously connection, connection (n) will initiate RecieveAsync before connection (n-1) and therefor connection (1) will be the last processed.
LoopToStartAccept will block so long as AcceptAsync returns false. This may be a rare scenario so a delay may needed to be added to ProcessAccept to simulate, but the proof would be the count of the poolOfAcceptEventArgs in the event of large volume simultaneous connections.
Great example and explanation, but a FIFO AcceptAsync process would greatly improve the durability and efficiency of this server.
|
|
|
|

|
good article, good writing style, detailed explanations within code. What else is there to ask for in an article?
|
|
|
|

|
Hi Stan,
was wondering if you would be available for a call to discuss your approach to sockets. I'm Tech Lead on a project and we have been considering using the appoach you took.
Thanks,
Hope to hear from you soon.
Stan Chatman
stan.chatman@avanade.com
Ph: 708.415.6770
|
|
|
|

|
now,i can one client connect server,send and reviced all ok! but,when multiple clients connect server,server do not send data to client i want to design a multiple clients chat base on SocketAsyncEventAgrs ! can you code a exmple? help me! very very thanks!
|
|
|
|

|
we want received data and send data if needs.
|
|
|
|

|
The code below is not sufficient to handle the situation where one computer sends multiple messages to the other before the second one responds.
(client send to server)
socket.send("message 1");
socket.send("message 2");
socket.send("message 3");
What i understand is, i thought windows system socket will queue the send buffer automatically and send to other computer in sequence.
What do you mean is not sufficient to handle? Or you mean your sample code didn't handle it?
|
|
|
|

|
Yes, Windows will do what you said. But the sample application code I gave is NOT designed to deal with that situation. My code allows for reading less than or equal to the number of bytes till the end of one message from the Windows receive-buffer. You would need to create code that allows for the possibility of receiving (1) greater than the number of bytes that would complete any message, (2) two, three, or more messages being in the receive buffer at the same time.
You would need code that deals with the situation where data from 2 or more different messages is read from the Windows system receive-buffer by the application on the server side. You need a mechanism to split the multiple messages. And you must deal with more possible scenarios.
You may want to bundle the messages on the client side and do a Send op that has multiple messages. It is often faster to send multiple messages and split them on the server side, assuming that multiple messages are ready to be sent.
I just tried to keep the code fairly simple to understand. After you understand the sample code, then you can work on coming up with your own code to send and split multiple messages sent at once, rather than needing to incur the overhead of networking lag with each message.
|
|
|
|

|
This is excellent article. The topic is presented in very understandable, exhausting way. Thanks a lot!
|
|
|
|

|
I have not yet downloaded the source code, but you have my 5 vote of 5 already. Very thorough article, pleasure to read.
|
|
|
|

|
Really well thought out and executed.
|
|
|
|

|
Excellent article, well explained
|
|
|
|

|
Hello, thank you very much inspired by this example I, but there is a problem of this: in HandleBadAccept function, Socket closed, acceptEventArgs not remove the reference to it into a AccepteSocket poolOfAcceptEventArgs, again, when out of use in bool willRaiseEvent = listenSocket.AcceptAsync (acceptEventArg); Department, there had been "turned off Safe Handle" exception, I think, in HandleBadAccept function in, acceptEventArgs.AcceptSocket.Close (); should be added after the code: acceptEventArgs.AcceptSocket = null; to avoid the above error.
|
|
|
|

|
Hi,
The library is working pretty good under windows7/vista.
Thank you again for the comments in the code.
Under Windows Server 2003 (x86/x64) the library is behaving totally differently and weird.
As soon as the listenSocket start the AcceptAsync, there is an incoming connection (the Completed event is triggered)
This is happeneing only under Windows Server 2003, the exact same code is used under windows7 and Vista and nothing is happeneing.
The listener is just waiting for a client to connect and then trigger Completed event which is normal.
On Windows Server 2003 it triggers the Completed event without any incoming connection.
This have been tested on 3 different windows server 2003 (all 3 from different environments) and its always the same issue
Once a client is connect so after a first AcceptAsync, no more connections are faisable ... no expection, it's stuck.
With a telnet, the connection is establish but without triggering any event in the code, without any handleing of the incoming bytes. Telnet is sure connected as it switch to input text mode.
I'm really confused and lost on this one ...
And I can't reproduce it on Win7/Vista, only Win2003 Srv do that.
All systems are update in terms of framework libraries (3.5 sp1)
Thank for the help
Alex .NET
|
|
|
|

|
I get this behaviour under WIN7 x64 and XP My fix is to assign null to acceptArgs.AcceptSocket after the Close() in HandleBadAccept() To allow for the next connection I set the socket option SocketOptionName.ReuseAddress
|
|
|
|

|
Hello,
This is a very cool article, I had many problems to implement the Microsoft article and with your explanations and source code, you made it really more clear )
I downloaded the zip from today on and ran it under "runLongTest" true, with 100,000 connexions, 1 message, message of 20,000 length. Its working pretty good with for a few minutes until a Stackoverflow occurs at SocketClient.cs:391
here is the ini file:
N
localhost
4444
c:\LogForSaeaTest\Client\
10000
100000
1
100
I run this tests under windows 7 x64
What can cause this Stackoverflow ?
voted 5/5
Regards
Alex .NET
|
|
|
|

|
I meet the problem too in win2003 x64
|
|
|
|

|
The problem come from CheckStack. Which loop, replace it by a classic loop While will fix the issue
Alex .NET
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
|
Use the .NET SocketAsyncEventArgs to write socket server code in C#
| Type | Article |
| Licence | CPOL |
| First Posted | 26 Jul 2010 |
| Views | 159,851 |
| Downloads | 12,158 |
| Bookmarked | 365 times |
|
|