C# 客户端接收:
private readonly IPAddress GroupAddress = IPAddress.Parse("255.255.255.255");
private readonly int GroupPort = 8088;
private static ActionListening uniqueInstance = new ActionListening();
private UdpClient listener;
public void Class1()
{
Thread thread = new Thread(new ThreadStart(StartListener));
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
} public void StartListener()
{
bool done = false;
try
{
if (listener == null)
{
listener = new UdpClient(GroupPort);
}
IPEndPoint groupEP = new IPEndPoint(GroupAddress, 11000); while (!done)
{
byte[] bytes = listener.Receive(ref groupEP); string resStr = Encoding.ASCII.GetString(bytes, 0, bytes.Length);
}
}
catch (Exception e)
{
}
finally
{
listener.Close();
} } Java服务器发送:
private boolean sendMessageToClient(String[] computerName,
String messageContent, int portNumber)
{
String methodName = "sendMessageToClient()";
DatagramSocket socket = null;
String machineName = null;
try
{
// generate buffer
byte[] buf = messageContent.getBytes();
// generate DatagramSocket instance
socket = new DatagramSocket();
int size = computerName.length;
for (int i = 0; i < size; i++)
{
try
{
machineName = computerName[i];
InetAddress address = InetAddress.getByName(computerName[i]); DatagramPacket packet = new DatagramPacket(buf, buf.length,
address, portNumber);
socket.send(packet);
}
catch (UnknownHostException e)
{ }
}
}
catch (IOException e)
{
return false;
}
catch (Exception e)
{
return false;
}
finally
{
try
{
if (socket != null)
{
socket.close();
}
}
catch (Exception e)
{
return false;
}
}
return true;
}
}大概就是这个样子,在XP下反应很快,及时收到,但在vista下就收不到了,请问有朋友教我吗
private readonly IPAddress GroupAddress = IPAddress.Parse("255.255.255.255");
private readonly int GroupPort = 8088;
private static ActionListening uniqueInstance = new ActionListening();
private UdpClient listener;
public void Class1()
{
Thread thread = new Thread(new ThreadStart(StartListener));
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
} public void StartListener()
{
bool done = false;
try
{
if (listener == null)
{
listener = new UdpClient(GroupPort);
}
IPEndPoint groupEP = new IPEndPoint(GroupAddress, 11000); while (!done)
{
byte[] bytes = listener.Receive(ref groupEP); string resStr = Encoding.ASCII.GetString(bytes, 0, bytes.Length);
}
}
catch (Exception e)
{
}
finally
{
listener.Close();
} } Java服务器发送:
private boolean sendMessageToClient(String[] computerName,
String messageContent, int portNumber)
{
String methodName = "sendMessageToClient()";
DatagramSocket socket = null;
String machineName = null;
try
{
// generate buffer
byte[] buf = messageContent.getBytes();
// generate DatagramSocket instance
socket = new DatagramSocket();
int size = computerName.length;
for (int i = 0; i < size; i++)
{
try
{
machineName = computerName[i];
InetAddress address = InetAddress.getByName(computerName[i]); DatagramPacket packet = new DatagramPacket(buf, buf.length,
address, portNumber);
socket.send(packet);
}
catch (UnknownHostException e)
{ }
}
}
catch (IOException e)
{
return false;
}
catch (Exception e)
{
return false;
}
finally
{
try
{
if (socket != null)
{
socket.close();
}
}
catch (Exception e)
{
return false;
}
}
return true;
}
}大概就是这个样子,在XP下反应很快,及时收到,但在vista下就收不到了,请问有朋友教我吗
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货