| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1639 人关注过本帖
标题:请教C#的UdpClient发送问题
只看楼主 加入收藏
hyg188
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2007-3-29
收藏
 问题点数:0 回复次数:2 
请教C#的UdpClient发送问题

请教UdpClient发送问题
我想在两台PC机A和B间用C#的 UdpClient传输数据, 如果两边都用网上下载的ezUDP小程序 , 那么A.B两台PC收.发均正常. 而我用C#的 UdpClient写了一个简单程序放在机A上, 机B上仍用ezUDP小程序, 结果是: 机A能收到机B发来的数据, 反之. 机B却不能收到机A发来的数据. 弄了好久都解决不了, 真不知为什么? 请哪位朋友指教一下,谢谢!
附:1.两台PC机设置: 机A: IP=192.168.1.100, Port= 2000.
机B: IP=192.168.1.1, Port= 1180.
2. 电缆: 两台PC直连, 两个RJ45扦头均是这头的1 .2 脚分别接那头的3 .6 脚.
3. C#的 UdpClient程序与发送有关的部份如下:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Text;

namespace UdpClientClient
{
public class Form1 : System.Windows.Forms.Form
{
private UdpClient sendUdp;
private IPEndPoint remoteIPEndPoint;
private IPAddress remoteIPAddr;
private string remoteIP = "192.168.1.2";
private int remotePort = 1180;

public Form1()
{
InitializeComponent();
}
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void btnSend_Click(object sender, System.EventArgs e)
{
try
{
remoteIPAddr = IPAddress.Parse(remoteIP);
remoteIPEndPoint = new IPEndPoint(remoteIPAddr, remotePort);
remoteIPEndPoint = new IPEndPoint(IPAddress.Parse(remoteIP), remotePort);
Wait();
sendUdp = new UdpClient(remotePort);
sendUdp.Connect(remoteIPEndPoint);

byte[] sendData = new Byte[5] { 128, 1, 1, 1, 128 };
sendUdp.Send(sendData, sendData.Length);
sendUdp.Close();
}
catch (Exception a)
{
ricRecBox.Text = a.ToString();
}

sendUdp.Close();

}

private void Wait()
{
int i,j,k;
k = 6;
for( i=0;i<8000;i++)
{
for (j = 0; j < 8000; j++)
{
k++;
k--;
}
}
}
}
}

搜索更多相关主题的帖子: UdpClient 
2007-03-30 11:13
draeag
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-6-1
收藏
得分:0 
private string remoteIP = "192.168.1.2";
机B: IP=192.168.1.1, Port= 1180.
我也没试过,也没研究,只是看上去上面两个IP地址不一样啊!
2007-08-31 10:32
jockey
Rank: 3Rank: 3
等 级:论坛游民
威 望:8
帖 子:977
专家分:52
注 册:2005-12-4
收藏
得分:0 
wait()是什么?

2007-08-31 12:09
快速回复:请教C#的UdpClient发送问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.031748 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved