HELP!!! How do I send an ACK packet in TCP IP Listener c# RRS feed

  • Question

  • I want to created TCP IP Listener  and communicate with medical  device . 

    Kindly advise us how to send ACK Packet from Server to Client (Medical device) 

    Tuesday, October 2, 2018 4:28 PM

All replies

  • using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Net;
    using System.Net.Sockets;
    namespace TCPServer
        class Program
            static void Main(string[] args)
                int recv;
                byte[] data = new byte[1024];
                IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 9050);
                Socket newsock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                Console.WriteLine("Waiting for client...");
                Socket client = newsock.Accept();
                IPEndPoint clienttep = (IPEndPoint)client.RemoteEndPoint;
                Console.WriteLine("Connected with {0} at port {1}", clienttep.Address, clienttep.Port);
                string welcome = "Welcome to my Server";
                data = Encoding.ASCII.GetBytes(welcome);
                client.Send(data, data.Lengt, SocketFlags.None);
                while (true)
                    data = new byte[1024];
                    recv = client.Receive(data);
                    if (recv == 0) break;
                    Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv));
                    client.Send(data,recv, SocketFlags.None);
                Console.WriteLine("Disconnected from {0}", clienttep.Address);

    Tuesday, October 2, 2018 5:19 PM
  • Hello.

    I would start with something like :

    namespace ClassLibrary1
        internal class SharedSocket
        public class Sender
            public Sender(SharedSocket ss) { }
        public class Receiver
            public Receiver(SharedSocket ss) { }
        public class CommunicationManager
            public CommunicationManager(Receiver r, Sender s) { }
            public void Run() { }
        public static class Program
            static void Main(string[] args)
                SharedSocket ss = new SharedSocket();
                Sender s = new Sender(ss);
                Receiver r = new Receiver(ss);
                CommunicationManager cm = new CommunicationManager(r, s);

    and try to implement interaction protocol in CommunicationManager using emulator of SharedSocket.

    And SharedSocket would implement separately just to have proper communication between Client and Server. Most likely it would be based on BackgrounWorker with some modification.

    Sincerely, Highly skilled coding monkey.

    Tuesday, October 2, 2018 6:27 PM
  • is there is any solution 
    Tuesday, August 6, 2019 9:05 AM
  • Solution to what?  Are you saying that in 10 months you have not been able to get a simple TCP communication working?

    The document you sent doesn't look like a TCP exchange.  TCP exchanges don't usually use terms like [ACK] and [NAK], because those are all handled by the protocol itself.  Event if it were so, the medical device would almost certainly not be the TCP Server.

    So, perhaps you should provide more detail about what it is you are trying to accomplish.

    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Tuesday, August 6, 2019 8:17 PM
  • Yup. Maybe he need UDP, raw socket, or even serial communication instead.

    The programming manual of device should have specified that.

    Wednesday, August 7, 2019 1:41 AM
  • >>Are you saying that in 10 months you have not been able to get a simple TCP communication working?

    And you would? 

    Can you answer few simple questions? 

    1. How many certified for medicine network solution you known?

    2. Would every solution which started with TCP?IP run to the end point over TCP/IP? Specially - medical.

    But, yes - 10 month to do nothing regards to the task is too long... 

    Sincerely, Highly skilled coding monkey.

    Wednesday, August 7, 2019 8:03 AM
  • Sorry, I didn't see how this code related with task in initial post. 

    Sincerely, Highly skilled coding monkey.

    Wednesday, August 7, 2019 8:04 AM
  • >>or even serial communication

    It worst - in medical systems it could be on initial TCP/IP and somewhere at the middle and very much at the end will go over serial. With all limits for serial. 

    I so several times how guys implement everything for messaging system on TCP/IP, test this on simple messages in local net... and fail on normal workload on real network regards to the simple serial buffer overflow on the end device.

    Sincerely, Highly skilled coding monkey.

    Wednesday, August 7, 2019 8:13 AM