Re: Asynchronous sockets and buffer size

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Sorry, I don't know what I expected with an explanation like that.

here's what my code is like with all the fluff cut out:

private void OnReceive(IAsyncResult asyn)
{
ObjectThing Job = (ObjectThing)asyn.AsyncState;
long BytesReceived = Job.s.EndReceive(asyn);

if (BytesReceived > 0)
{
ProcessData(Job);
Job.s.BeginReceive(Job.buffer, 0, Job.buffer.Length, 0, new AsyncCallback(this.OnReceive), Job);
}

else
{
Job.s.Close();
Job.s = null;
}

}

private void OnSend(IAsyncResult asyn)
{
ObjectThing Job = (ObjectThing)asyn.AsyncState;
Job.s.EndSend(asyn);
Job.s.BeginReceive(Job.buffer, 0, Job.buffer.Length, 0, new AsyncCallback(this.OnReceive), Job);
}

private void OnConnect(IAsyncResult asyn)
{

ObjectThing Job = (ObjectThing)asyn.AsyncState;
Job.s.EndConnect(asyn);
Job.s.BeginSend(Encoding.ASCII.GetBytes(Job.data + "\r\n"), 0, Encoding.ASCII.GetBytes(Job.data + "\r\n").Length, 0, new AsyncCallback(this.OnSend), Job);

}


Job.s is the socket and i call Job.s.BeginConnect(...) to start.


Michael Rubinstein wrote:
Matthew, I am not quite sure which 'excellent MSDN example' you were following. Normally TCP/IP servers (I assume you do TCP/IP) do not imitate disconnect - clients do. On the server side do not terminate client connection until the client disconnects - BeginReceive() on the server side returns 0, and you will not loose data.

Michael
.



Relevant Pages

  • Threads java.lang.NullPointerException
    ... I ve been working on a simple chat server program and it works when the ... server handles one client at the time. ... private JTextField nameField; ... private void openthrows IOException ...
    (comp.lang.java.help)
  • Re: Threads java.lang.NullPointerException
    ... >server handles one client at the time. ... > private JTextField nameField; ... > private void openthrows IOException ...
    (comp.lang.java.help)
  • implements Runnable???
    ... Hello there I am trying to develop a simple multithreaded chat server ... the class Server which creates an instance of it to handle the client ... In the class ChatHandler inside the runmethod the line code: ... private void processRequests() throws IOException ...
    (comp.lang.java.help)
  • handling server clicks after client side script runs
    ... for onClick there is a javascript. ... private void controlButton_ServerClick(object sender, ImageClickEventArgs ... This way, when the client clicks the image, javascript handles it at client ... I am able to call the controlButton_ServerClick() server side function ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: BeginAccept callback problem
    ... I'm trying to develop a server that listens to incoming calls using ... private void btnStart_Click ... Socket listener = ar.AsyncState; ...
    (microsoft.public.dotnet.languages.csharp)