[Mono-list] simple socket code on osx fails to flush
Carlo Kok
ck at remobjects.com
Wed Aug 29 19:27:58 UTC 2012
I'm probably missing something simple, but this following code on OSX
sometimes doesn't properly send every bit before closing when talking to
OSX from Windows (over network).
At first I thought it was my network but a colleague had at the same
issue at home. What am I missing? If i set a breakpoint on the shutdown
(in monodevelop) it does end up sending everything.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Net;
using System.Runtime.InteropServices;
using System.Threading;
using System.Net.Sockets;
namespace msock
{
class Program {
static void Main (string[] args)
{
TcpListener t = new TcpListener (1118);
t.Start ();
while (true) {
var socket = t.AcceptSocket();
var x = new byte[130400];
for (int i = 0; i < x.Length; i ++)
x[i] = (byte)((int)('a')+(i % 26));
x[x.Length-4] = (int)'D';x[x.Length-3] =
(int)'O';x[x.Length-2] = (int)'N';x[x.Length-1] = (int)'E';
SocketError er;
int n;
n= socket.Send(x, 0, x.Length,
SocketFlags.None, out er);
socket.Shutdown(SocketShutdown.Both);
socket.Close();
}
}
}
}
More information about the Mono-list
mailing list