Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Socket.Receive() will only obtain the first datagram each call. Verify there is more than 1382 bytes sent by the client side in the first call.</p> <p>If there is more data to be sent then either have the client queue it up for one Send call, or continuously call Receive() and append onto another buffer until you know it's completed.</p> <p>Edited for example: What you're looking for is non-blocking IO. One way to implement it is lined out <a href="http://msdn.microsoft.com/en-us/library/dxkwh6zw.aspx" rel="nofollow">here</a>. If you have a class per client-connection, it might look like this:</p> <pre><code>internal class Server { private static void Main(string[] args) { IPAddress localAddr = IPAddress.Parse(args[0]); System.Console.WriteLine("The local IP is {0}", localAddr); Int32 port = int.Parse(args[1]); System.Console.WriteLine("The port is {0}", port); TcpListener myListener = new TcpListener(localAddr, port); byte[] bytes = new byte[15000]; string sem = ""; do { Console.Write("Waiting"); myListener.Start(); Socket mySocket = myListener.AcceptSocket(); var clientConn = new ClientConnection(mySocket); } while (true); } } public class ClientConnection { private const int BUFFER_SIZE = 15000; readonly private byte[] _buffer = new byte[BUFFER_SIZE]; readonly private Socket _socket; readonly private StringBuilder _output = new StringBuilder(); public ClientConnection(Socket socket) { _socket = socket; _socket.BeginReceive(_buffer, 0, BUFFER_SIZE, SocketFlags.None, ReadCallback, null); } private void ReadCallback(IAsyncResult ar) { var read = _socket.EndReceive(ar); if (read &gt; 0) { // receiving the hl7 message string receiveMessage = Encoding.ASCII.GetString(_buffer, 0, read); _output.Append(receiveMessage); _socket.BeginReceive(_buffer, 0, BUFFER_SIZE, SocketFlags.None, ReadCallback, null); } else { // write out the hl7 message to a receiving folder DateTime currentDate = DateTime.Now; long eTicks = currentDate.Ticks; System.IO.File.WriteAllText(@"y:\results\" + eTicks + ".hl7", _output.ToString()); SendAcknowledgement(); } } private void SendAcknowledgement() { // build the acknowledgemnent message to send back to the client } } </code></pre> <p>I didn't verify this, but it should get you in the right direction. I assumed that when the client is done sending data, then the server should stop reading it. I also assumed that your do { } was the start of an infinite loop that waited for new connections. You can also make use of BeginAccept() to make that portion of the code non-blocking, but that depends on your use case if you need to.</p> <p>Note that every connection opened this way will result in a new ThreadPool thread.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload