/** * 单例 * @param point * @return */ public static judpSocketManager GetInstance(UDPEndPoint point) { if (instance == null) { instance = new judpSocketManager(point); } return(instance); }
/** * copy input data from the source stream to the target stream * @param source - input stream to read from * @param target - output stream to write to * @throws IOException */ //public static void copy(UDTInputStream source, UDTOutputStream target) //{ // Copy(source, target, -1, false); //} /** * copy input data from the source stream to the target stream * @param source - input stream to read from * @param target - output stream to write to * @param size - how many bytes to copy (-1 for no limit) * @param flush - whether to flush after each write * @throws IOException */ //public static void Copy(UDTInputStream source, UDTOutputStream target, long size, bool flush){ // byte[]buf=new byte[8*65536]; // int c; // long read=0; // while(true){ // c=source.Read(buf); // if(c<0)break; // read+=c; // //System.out.println("writing <"+c+"> bytes"); // target.Write(buf, 0, c); // if(flush)target.Flush(); // if(read>=size && size>-1)break; // } // if(!flush)target.Flush(); //} /** * perform UDP hole punching to the specified client by sending * a dummy packet. A local port will be chosen automatically. * * @param client - client address * @return the local port that can now be accessed by the client * @throws IOException */ public static void DoHolePunch(UDPEndPoint endpoint, EndPoint point) { UDPUserToken p = new UDPUserToken((IPEndPoint)point); p.Buffer = new byte[1]; p.Length = 1; //p.setAddress(client); //p.setPort(clientPort); endpoint.SendRaw(p); }
/** * perform UDP hole punching to the specified client by sending * a dummy packet. A local port will be chosen automatically. * * @param client - client address * @return the local port that can now be accessed by the client * @throws IOException */ public static void doHolePunch(UDPEndPoint endpoint, IPAddress client, int clientPort) { byte[] p = new byte[1]; endpoint.sendRaw(p); }
private judpSocketManager(UDPEndPoint point) { this.endPoint = point; StartGC(); }