救命!!!如何在TCP IP侦听器中发送ACK数据包c# [英] HELP!!! How do I send an ACK packet in TCP IP Listener c#

查看:216
本文介绍了救命!!!如何在TCP IP侦听器中发送ACK数据包c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建TCP IP侦听器 和医疗沟通 设备。 


请告知我们如何从服务器向客户端发送ACK数据包(医疗设备) 



 

解决方案

< pre class ="prettyprint">使用System;
使用System.Collections.Generic;
使用System.Linq;
使用System.Text;
使用System.Net;
使用System.Net.Sockets;

名称空间TCPServer
{
class程序
{
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);

newsock.Bind(ipep);
newsock.Listen(10);

Console.WriteLine(" Waiting for client ...");

Socket client = newsock.Accept();

IPEndPoint clienttep =(IPEndPoint)client.RemoteEndPoint;

Console.WriteLine("与端口{1}的{0}连接",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(" Disachedcted from {0}",clienttep.Address);

client.Close();
newsock.Close();
}
}
}




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) 

 

解决方案

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);

            newsock.Bind(ipep);
            newsock.Listen(10);

            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);

            client.Close();
            newsock.Close();
        }
    }
}



这篇关于救命!!!如何在TCP IP侦听器中发送ACK数据包c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆