using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;namespace SocketUDPClient2
{
class Program
{
public class Client_Th
{
static void Main(string[] args)throws IOException
{
DatagramSocket socket=new DatagramSocket();//创建套接字
byte buf[]=new Byte [256];
InetAddress=InetAddress.getByName("192.168.1.108");//服务器IP
DatagramPacket packet=new DatagramPacket(buf,buf,Length,address,2000);//创建要发送的数据报对象
socket.send(packet);//发送数据报
packet=new DatagramPacket(buf,buf,length);//创建要接收的数据包对象
socket.receive(packet);//接收数据报
String receive=new String(packet getData());
System.out.println("The string receive from server:"+receive);
Socket.close(); }
}
}
}我想用数据报Socket做一个与平板通信的PC客户端,这样写在throws和Datagram那里会报错= =?
UDPsocket
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;namespace SocketUDPClient2
{
class Program
{
public class Client_Th
{
static void Main(string[] args)throws IOException
{
DatagramSocket socket=new DatagramSocket();//创建套接字
byte buf[]=new Byte [256];
InetAddress=InetAddress.getByName("192.168.1.108");//服务器IP
DatagramPacket packet=new DatagramPacket(buf,buf,Length,address,2000);//创建要发送的数据报对象
socket.send(packet);//发送数据报
packet=new DatagramPacket(buf,buf,length);//创建要接收的数据包对象
socket.receive(packet);//接收数据报
String receive=new String(packet getData());
System.out.println("The string receive from server:"+receive);
Socket.close(); }
}
}
}我想用数据报Socket做一个与平板通信的PC客户端,这样写在throws和Datagram那里会报错= =?
UDPsocket
http://blog.csdn.net/nanwang314/article/details/6205310
http://blog.163.com/hulei_accp/blog/static/106898640201171185156716/
这是你的main函数。你别throws。在程序里try,catch掉。