namespace Microsoft.Rfid.Reader.Driver.Acme
{
internal class UdpTransport
{
private UdpClient client;
private UdpClient asynClient;
private ILogger logger;
private AcmeReaderLayer readerLayer;
private ManualResetEvent asynEvent;
private const int clientPort = 4567;
private const int asynClientPort = 4568;
private static string localHost = Dns.GetHostName();
private Thread asynReceiveThread;
private string host;
private int port;
public UdpTransport()
{
}
public void Init(TcpTransportSettings settings,ILogger logger, AcmeReaderLayer readerLayer)
{
lock (this)
{
try
{
this.logger = logger;
this.readerLayer = readerLayer;
this.host = settings.Host;
this.port = settings.Port;
asynEvent = new ManualResetEvent(true);
IPAddress ip = Dns.GetHostAddresses(localHost)[0];
this.client = new UdpClient(new IPEndPoint(ip, clientPort));
this.asynClient = new UdpClient(new IPEndPoint(ip, asynClientPort));
}
catch (Exception ex)
{
logger.Error("UdpTransport Contrusture Error:" + ex.ToString());
}
} private const int clientPort = 4567;
private const int asynClientPort = 4568; 这两个断口,现在是固定的
现在想这的常数值,变位动态可变的在下面的两句里被引用
this.client = new UdpClient(new IPEndPoint(ip, clientPort));
this.asynClient = new UdpClient(new IPEndPoint(ip, asynClientPort));
要问的问题是:
在MS的BIZTALK RFID 中,每加一设备,就要走到INIT()里
而每个设备要两个端口,如何实现端口不重复?
描述:
如有一个设备
A INTI 占 5000 和5001而再加入个设备B 则要分配其他的两个端口号,且这两个端口要未被使用。加C
端口不允许重复 如何搞啊?
{
internal class UdpTransport
{
private UdpClient client;
private UdpClient asynClient;
private ILogger logger;
private AcmeReaderLayer readerLayer;
private ManualResetEvent asynEvent;
private const int clientPort = 4567;
private const int asynClientPort = 4568;
private static string localHost = Dns.GetHostName();
private Thread asynReceiveThread;
private string host;
private int port;
public UdpTransport()
{
}
public void Init(TcpTransportSettings settings,ILogger logger, AcmeReaderLayer readerLayer)
{
lock (this)
{
try
{
this.logger = logger;
this.readerLayer = readerLayer;
this.host = settings.Host;
this.port = settings.Port;
asynEvent = new ManualResetEvent(true);
IPAddress ip = Dns.GetHostAddresses(localHost)[0];
this.client = new UdpClient(new IPEndPoint(ip, clientPort));
this.asynClient = new UdpClient(new IPEndPoint(ip, asynClientPort));
}
catch (Exception ex)
{
logger.Error("UdpTransport Contrusture Error:" + ex.ToString());
}
} private const int clientPort = 4567;
private const int asynClientPort = 4568; 这两个断口,现在是固定的
现在想这的常数值,变位动态可变的在下面的两句里被引用
this.client = new UdpClient(new IPEndPoint(ip, clientPort));
this.asynClient = new UdpClient(new IPEndPoint(ip, asynClientPort));
要问的问题是:
在MS的BIZTALK RFID 中,每加一设备,就要走到INIT()里
而每个设备要两个端口,如何实现端口不重复?
描述:
如有一个设备
A INTI 占 5000 和5001而再加入个设备B 则要分配其他的两个端口号,且这两个端口要未被使用。加C
端口不允许重复 如何搞啊?
解决方案 »
- controlNavigator控件刚托到上面为什么上翻下翻按钮是灰色的
- 正则表达式,符合某一规则
- vc 用winPcap捕获的数据包与用c# socket接收到的数据包问题
- 添加记录时一个奇怪的问题
- 请问 如何 判断文件的类型啊?
- SqlDataAdapter.Fill的方法得到的dataset有主键吗,好像没有,怎么样才使dataset有主键
- 很奇怪的动态表格问题
- 急求sharepoint2003的webpart的教程,C#的 急求!!!!!
- PrintDocument 组件
- 求助C#中接口的作用?
- 用c#怎样做类似outlook2003的界面
- 用webRequest如何取得网址返回的状态码?
如得到一个数是不6000,而一次我要两个端口好,我可以用6001,
但如何让第二次再产生的随机数和第一次产生的不相同(即和6000 、6001不同)?最好给点参考代码 谢谢代码在INTI() 实现要,INIT()的执行过程,加一个设备,执行一次INIT(),
就说要在INIT()里做判断
class Program
{
//定义一个ArrayList,用于存储已分配的端口号
public static ArrayList list = new ArrayList();
public static void Main()
{
string str = Console.ReadLine();
while (str != "exit")
{
DevicePort devicePort = GetPort();
Console.WriteLine("FirstPort: " + devicePort.firstPort.ToString() + "\t" + "SecondPort: " + devicePort.secondPort.ToString());
str = Console.ReadLine();
}
}
public static DevicePort GetPort()
{
Random rd = new Random();
int[] ports = new int[2];
for (int i = 0; i < 2; i++)
{
int port = rd.Next(5000, 8000);
while (list.Contains(port))
{
port = rd.Next(5000, 8000);
}
list.Add(port);
ports[i] = port;
}
DevicePort devicePort = new DevicePort();
devicePort.firstPort = ports[0];
devicePort.secondPort = ports[1];
return devicePort;
} }
struct DevicePort
{
public int firstPort;
public int secondPort;
}输出如下:
FirstPort: 7228 SecondPort: 5639
FirstPort: 5661 SecondPort: 5586
FirstPort: 6299 SecondPort: 7714
FirstPort: 5537 SecondPort: 6014
FirstPort: 6989 SecondPort: 5682
FirstPort: 5798 SecondPort: 5386
FirstPort: 6175 SecondPort: 5970
FirstPort: 6322 SecondPort: 6302
FirstPort: 6374 SecondPort: 5142
FirstPort: 5089 SecondPort: 6354
FirstPort: 6312 SecondPort: 5770
FirstPort: 6459 SecondPort: 6101
FirstPort: 5174 SecondPort: 7313
exit
{
public partial class Form1 : Form
{
public static ArrayList list = new ArrayList(); public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
DevicePort devicePort = GetPort();
textBox1.Text = devicePort.firstPort.ToString();
}
public static DevicePort GetPort()
{
Random rd = new Random();
int[] ports = new int[2];
for (int i = 0; i < 2; i++)
{
int port = rd.Next(5000, 8000);
while (list.Contains(port))
{
port = rd.Next(5000, 8000);
}
list.Add(port);
ports[i] = port;
}
DevicePort devicePort = new DevicePort();
devicePort.firstPort = ports[0];
devicePort.secondPort = ports[1];
return devicePort;
} struct DevicePort
{
public int firstPort;
public int secondPort;
} }
}Error 1 Inconsistent accessibility: return type 'random.Form1.DevicePort' is less accessible than method 'random.Form1.GetPort()' C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\random\random\Form1.cs 57 34 random这是什么意思?
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private ArrayList list = new ArrayList();
private DevicePort GetPort()
{
Random rd = new Random();
int[] ports = new int[2];
for (int i = 0; i < 2; i++)
{
int port = rd.Next(5000, 8000);
while (list.Contains(port))
{
port = rd.Next(5000, 8000);
}
list.Add(port);
ports[i] = port;
}
DevicePort devicePort = new DevicePort();
devicePort.firstPort = ports[0];
devicePort.secondPort = ports[1];
return devicePort;
} private void button2_Click(object sender, EventArgs e)
{
DevicePort devicePort = GetPort();
this.textBox2.Text = devicePort.firstPort.ToString();
this.textBox3.Text = devicePort.secondPort.ToString();
} }
struct DevicePort
{
public int firstPort;
public int secondPort;
}
}
public int[] GetPort()
{
Random rd = new Random();
int[] ports = new int[2];
int port = rd.Next(1, 5);
while (list.Contains(port)||list.Contains(port+1)||list.Contains(5) )
{
port = rd.Next(1, 5);
}
list.Add(port);
list.Add(port+1);
ports[0] = port;
ports[1] = ports[0] + 1;
return ports ;
}
也可以的