From owner-freebsd-questions@FreeBSD.ORG Tue Feb 16 19:42:56 2010 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id AA71C1065733 for ; Tue, 16 Feb 2010 19:42:55 +0000 (UTC) (envelope-from nlandys@gmail.com) Received: from qw-out-2122.google.com (qw-out-2122.google.com [74.125.92.27]) by mx1.freebsd.org (Postfix) with ESMTP id 94B758FC16 for ; Tue, 16 Feb 2010 19:42:55 +0000 (UTC) Received: by qw-out-2122.google.com with SMTP id 8so841430qwh.7 for ; Tue, 16 Feb 2010 11:42:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type; bh=QGP6gblW0I08r5yhiAjdA0BhitfKwOvg3I2EHXxp1z8=; b=Jn1EBS8OIUzsrnV7kMK+3vdpFmbWRNcgzNw/Z9FYd2CMBYRPbKyGYOaEKnVVQpt1F8 YeminIqx5GUi7H/hC1GP8Wlm2rE4fd5okllFA5H/ZfS25PX3C8SVKzR9g3bgXwpk8wjr Sg3ZX2jBEariH8KdxgN12aMEwtWAEFaiDZCsc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=sWRLfEOhUMWXaLdRWseJIj92AuN3xSgBw8Wsq7T7jtoh0GiaNbt2VA//BdNtGU+YyB 8dd5qKg0GAjVSobOw05gbE/vlK02tET0ArSRAhAkC03BiPAzk89lxBKmzTZ9Eny/yNRJ Dy/gWVIPqoFW6tqi5FrGL/DDWo/S1+lCOV79g= MIME-Version: 1.0 Received: by 10.229.110.199 with SMTP id o7mr3540562qcp.76.1266349374807; Tue, 16 Feb 2010 11:42:54 -0800 (PST) Date: Tue, 16 Feb 2010 11:42:54 -0800 Message-ID: <560f92641002161142m1e85b647u5f0870896be44958@mail.gmail.com> From: Nerius Landys To: FreeBSD Mailing List Content-Type: text/plain; charset=ISO-8859-1 Subject: netcat (/usr/bin/nc) buffer size too small - alternate utilities? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Feb 2010 19:42:56 -0000 I'm communicating with a server that uses UDP packets. The server receives a UDP packet, and responds with a UDP packet by sending one to the initial sender. The request packets are always very small in size, but the response UDP packets can be up to 9216 bytes in size. I am using netcat like so: echo "$REQUEST_BODY" | /usr/bin/nc -w 1 -u "$PLAYERDB_HOST" "$PLAYERDB_PORT" The response always gets truncated to 1024 bytes using netcat. I wrote my own silly version of netcat specifically suited to my needs over UDP, in Java. I then call it like so: echo "$REQUEST_BODY" | /usr/local/bin/java SendUDP "$PLAYERDB_HOST" "$PLAYERDB_PORT" (Source code at the end of this message.) With my Java program, I'm able to get up to 9216 bytes in my UDP response packet; the response won't be truncated to 1024 bytes like in netcat. Now I've read the netcat manpage and it says nothing about any buffer size or ways to increase it. I don't really want to use my Java program because starting up a JVM for each server query is very expensive. Any ideas of any other tools like netcat that will enable me to receive UDP packets up to 9216 bytes in size? Here's the source code for my SendUDP.java code in case you want to see it: ================================ import java.io.*; import java.net.*; public class SendUDP { private final static int BUFF_SIZE = 9216; public static void main(String[] args) throws IOException { if (args.length != 2) { throw new IllegalArgumentException ("\nUsage:\n" + " java SendUDP \n" + "Sends standard input."); } if (!(System.in.available() > 0)) { throw new IllegalStateException("expected system input to send"); } final InetAddress sendHost = InetAddress.getByName(args[0]); final int sendPort = Integer.parseInt(args[1]); final byte[] buff = new byte[BUFF_SIZE]; int read; int len = 0; while ((read = System.in.read()) >= 0) { if (len >= buff.length) throw new IllegalStateException("too much input, won't fit"); buff[len++] = (byte) read; } DatagramPacket pack = new DatagramPacket(buff, len); pack.setLength(len); final DatagramSocket sock = new DatagramSocket(); sock.connect(sendHost, sendPort); sock.send(pack); pack = new DatagramPacket(buff, buff.length); sock.receive(pack); System.out.write(buff, 0, pack.getLength()); } }