TCP/Socket Qn

We use ServerSocket.accept() on the server-side to get a communcation "end-point" between the server and the client. The object returned is a Socket object. We typically spawn a thread to handle subsequent communication between these 2 end-points using the returned Socket handle. The server will end up getting many Socket handle over time for servicing requests from clients:
while (true) {
Socket s=serverSocket.accept();
new HandlerThread(s).start();
In most cases, the communications between the end-points will be conducted using TCP packet. The TCP packet includes information like the address of the client and the server, the client port and the server port and some other checksum information. The question now is, for any incoming packet destined for this server (based on the port number), how does it know to arrive at a particular Socket handle?
Ben

This won't work if I run 2 applications on the client side. Eg, 2 ftp clients pointing to the same server.
Rdgs,
Ben

Similar Messages

  • TCP Socket connection in CLOSE_WAIT status and not getting closed

    I am facing an issue with the TCP socket connections not getting closed and they are in CLOSE_WAIT status for ever.
    As a part of batch process in our application, emails are sent with 4 embedded images. These images are downloaded from 3rd party site with IP say "UUU.XXX.YYY.ZZZ"
    The images are embedded to email as follows
    1. An URL object is created with the site url.
    URL urlPhoto = new
    URL("http://UUU.XXX.YYY.ZZZ/email/photos.jpg");
    2.     The image cid is created with the URL object and the image name
    HtmlEmail htmlEmail = new HtmlEmail();
    String cid1 = htmlEmail.embed(urlPhoto,
    "photo.jpg");
    3.     The image cid is added to the email template by replacing the ${cid1} and the email is sent.
    <td valign="top">
                   <img src="cid:${cid1}" width="279" height="274">
              </td>
    When a mail is sent, 4 new TCP connections are opened and are put in CLOSE_WAIT status for ever. For every mail sent 4 new connections are opened. In UNIX there is an upper limit on the number of open file handles (defaults to 1024) at any point of time. The open TCP connection has the underlying socket in CLOSE_WAIT status and is not getting closed at all. When the upper limit (1024) is reached the batch process is throwing the following exception and terminates.
    Caused by: com.inet.tds.ap: java.net.SocketExceptionjava.net.SocketException: Too many open files
    at com.inet.tds.am.a(Unknown Source)
    at com.inet.tds.TdsDriver.a(Unknown Source)
    at com.inet.tds.TdsDriver.connect(Unknown Source)
    at java.sql.DriverManager.getConnection(DriverManager.java:525)
    at java.sql.DriverManager.getConnection(DriverManager.java:171)
    at com.hcomemea.batchprocess.dataaccess.database.BaseJdbcDao.openConnection(BaseJdbcDao.java:106)
    ... 12 more
    When I run the command lsof in UNIX which list the open file handles in the system
    $ /usr/sbin/lsof -p 22933 -i | grep CLOSE_WAIT
    java 22933 build_master 297u IPv6 129841943 TCP integration.com:47929->UUU.XXX.YYY.ZZZ:http (CLOSE_WAIT)
    java 22933 build_master 298u IPv6 129841947 TCP integration.com:47933->UUU.XXX.YYY.ZZZ:http (CLOSE_WAIT)
    java 22933 build_master 299u IPv6 129841950 TCP integration.com:47936->UUU.XXX.YYY.ZZZ:http (CLOSE_WAIT)
    java 22933 build_master 300u IPv6 129841970 TCP integration.com:47952->UUU.XXX.YYY.ZZZ:http (CLOSE_WAIT)
    ���list of 935 connections similarly�
    I tried 2 solutions
    1. Got the HttpURLConnection from the URL object and invoked disconnect method on the same. But it doesn�t work.
    2. Ran the batch process java program with the parameter �Dhttp.keepAlive=false to close the underlying connection but didn�t help.
    I need the underlying sockets to be closed and not put in CLOSE_WAIT status after sending the mail.
    Is it the problem with the embed method of HtmlEmail object not closing the underlying socket connection.
    If anyone has faced this issue before, kindly let me know the possible solutions for the same ASAP.
    Thank you,
    Ramesh G

    This sounds more like a problem due to connection pooling at middle tier/application server.
    If that has been ruled out, then you might to enable DCD or set expiry time on the server.

  • Receiving data through TCP Socket

    Hi all,
    I am trying to receive some data through TCP Socket from the
    server using XMLSocketClass. Ther server is responding with some
    data. But I can't access this data in my application. Pls tell me
    the reasons for not working of handler private function
    dataHandler(event:DataEvent):void .
    =============================================================================
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="absolute">
    <mx:Script>
    <![CDATA[
    import mx.controls.Alert;
    import mx.collections.ArrayCollection;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.DataEvent;
    import flash.events.IOErrorEvent;
    import flash.net.XMLSocket;
    private var socket:XMLSocket;
    private var nextId:int;
    private var events:ArrayCollection = new ArrayCollection();
    public static var host:String = "34.234.43.97";
    public static var port:Number = 8002;
    public var xml:XML;
    private function connectToServer():void
    socket = new XMLSocket();
    socket.addEventListener(DataEvent.DATA, dataHandler);
    configureListeners(socket);
    socket.connect(host, port);
    //This function is Not working
    private function dataHandler(event:DataEvent):void {
    Alert.show("dataHandler: " + event.data);
    xml = new XML(event.data);
    Alert.show(xml); }
    private function
    configureListeners(dispatcher:IEventDispatcher):void {
    dispatcher.addEventListener(Event.CLOSE, closeHandler);
    dispatcher.addEventListener(Event.CONNECT, connectHandler);
    dispatcher.addEventListener(DataEvent.DATA, dataHandler);
    dispatcher.addEventListener(IOErrorEvent.IO_ERROR,
    ioErrorHandler);
    dispatcher.addEventListener(ProgressEvent.PROGRESS,
    progressHandler);
    dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR,
    securityErrorHandler);
    private function closeHandler(event:Event):void {
    trace("closeHandler: " + event);
    private function ioErrorHandler(event:IOErrorEvent):void {
    trace("ioErrorHandler: " + event);
    private function progressHandler(event:ProgressEvent):void {
    trace("progressHandler loaded:" + event.bytesLoaded + "
    total: " + event.bytesTotal);
    private function
    securityErrorHandler(event:SecurityErrorEvent):void {
    trace("securityErrorHandler: " + event);
    /* private function dataHandler(event:DataEvent):void {
    trace("dataHandler: " + event);
    private function connectHandler(event:Event):void
    var obj:Object = new Object();
    obj.id = nextId++;
    obj.eventName="connect";
    obj.timestamp = new Date().valueOf();
    events.addItem(obj);
    private function sendData():void
    var xmlvalue:String=txtData.text.toString() ;
    var xmlfile:String =
    "<command>SndIns<parameter1>0x06</parameter1><parameter2>0x00</parameter2><parameter3>0x7 1</parameter3><parameter4>0x0F</parameter4><parameter5>0x11</parameter5><parameter6>0xFF</ parameter6></command>";
    socket.send(xmlfile);
    Alert.show(xmlfile);
    ]]>
    </mx:Script>
    <mx:HBox width="80%" horizontalAlign="center">
    <mx:TextInput id="txtData" name=""/>
    <mx:Button id="btnConnect" label="Connect"
    click="connectToServer();btnConnect.enabled = false"/>
    <mx:Button id="btnSend" label="Send Data"
    click="sendData()"/>
    <!--<mx:Button label="getData" id="btnGet"
    click="getData()"/>-->
    </mx:HBox>
    <mx:HBox x="10" y="30" width="100%">
    <mx:DataGrid width="80%" height="100%"
    dataProvider="{xml}">
    <mx:columns>
    <mx:Array>
    <mx:DataGridColumn headerText="Event Name"
    dataField="eventName"/>
    </mx:Array>
    </mx:columns>
    </mx:DataGrid>
    </mx:HBox>
    </mx:Application>

    Hi all,
    I am trying to receive some data through TCP Socket from the
    server using XMLSocketClass. Ther server is responding with some
    data. But I can't access this data in my application. Pls tell me
    the reasons for not working of handler private function
    dataHandler(event:DataEvent):void .
    =============================================================================
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="absolute">
    <mx:Script>
    <![CDATA[
    import mx.controls.Alert;
    import mx.collections.ArrayCollection;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.DataEvent;
    import flash.events.IOErrorEvent;
    import flash.net.XMLSocket;
    private var socket:XMLSocket;
    private var nextId:int;
    private var events:ArrayCollection = new ArrayCollection();
    public static var host:String = "34.234.43.97";
    public static var port:Number = 8002;
    public var xml:XML;
    private function connectToServer():void
    socket = new XMLSocket();
    socket.addEventListener(DataEvent.DATA, dataHandler);
    configureListeners(socket);
    socket.connect(host, port);
    //This function is Not working
    private function dataHandler(event:DataEvent):void {
    Alert.show("dataHandler: " + event.data);
    xml = new XML(event.data);
    Alert.show(xml); }
    private function
    configureListeners(dispatcher:IEventDispatcher):void {
    dispatcher.addEventListener(Event.CLOSE, closeHandler);
    dispatcher.addEventListener(Event.CONNECT, connectHandler);
    dispatcher.addEventListener(DataEvent.DATA, dataHandler);
    dispatcher.addEventListener(IOErrorEvent.IO_ERROR,
    ioErrorHandler);
    dispatcher.addEventListener(ProgressEvent.PROGRESS,
    progressHandler);
    dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR,
    securityErrorHandler);
    private function closeHandler(event:Event):void {
    trace("closeHandler: " + event);
    private function ioErrorHandler(event:IOErrorEvent):void {
    trace("ioErrorHandler: " + event);
    private function progressHandler(event:ProgressEvent):void {
    trace("progressHandler loaded:" + event.bytesLoaded + "
    total: " + event.bytesTotal);
    private function
    securityErrorHandler(event:SecurityErrorEvent):void {
    trace("securityErrorHandler: " + event);
    /* private function dataHandler(event:DataEvent):void {
    trace("dataHandler: " + event);
    private function connectHandler(event:Event):void
    var obj:Object = new Object();
    obj.id = nextId++;
    obj.eventName="connect";
    obj.timestamp = new Date().valueOf();
    events.addItem(obj);
    private function sendData():void
    var xmlvalue:String=txtData.text.toString() ;
    var xmlfile:String =
    "<command>SndIns<parameter1>0x06</parameter1><parameter2>0x00</parameter2><parameter3>0x7 1</parameter3><parameter4>0x0F</parameter4><parameter5>0x11</parameter5><parameter6>0xFF</ parameter6></command>";
    socket.send(xmlfile);
    Alert.show(xmlfile);
    ]]>
    </mx:Script>
    <mx:HBox width="80%" horizontalAlign="center">
    <mx:TextInput id="txtData" name=""/>
    <mx:Button id="btnConnect" label="Connect"
    click="connectToServer();btnConnect.enabled = false"/>
    <mx:Button id="btnSend" label="Send Data"
    click="sendData()"/>
    <!--<mx:Button label="getData" id="btnGet"
    click="getData()"/>-->
    </mx:HBox>
    <mx:HBox x="10" y="30" width="100%">
    <mx:DataGrid width="80%" height="100%"
    dataProvider="{xml}">
    <mx:columns>
    <mx:Array>
    <mx:DataGridColumn headerText="Event Name"
    dataField="eventName"/>
    </mx:Array>
    </mx:columns>
    </mx:DataGrid>
    </mx:HBox>
    </mx:Application>

  • Problems sending files throught TCP sockets

    I would like to transfer a file throught a tcp socket, here there is what the sender program does :
    try{
         File localFile = new File("shared/"+fileName);
         DataOutputStream oos = new DataOutputStream(socket.getOutputStream());     
         DataInputStream fis = new DataInputStream(new FileInputStream(localFile));
         while(fis.available() > 0){
              oos.writeByte(fis.readByte());
         catch(Exception e){}here what the receiver program does:
         try{
         File downloadFile = new File("incoming/"+fileName);
         downloadFile.createNewFile();
         ois = new DataInputStream(connectionSocket.getInputStream());
         fos = new DataOutputStream(new FileOutputStream(downloadFile));
         while(ois.available() > 0){
              fos.writeByte(ois.readByte());
         catch(Exception e){}
    }Where i m wrong? it doesnt work :( , it just create the new file in the incoming folder, but its size remains 0 byte :(
    help a newbye please :D

    Your problem is probably related to the use of available. This is the amount that is currently in the buffer that you can read without blocking. For network programming you should expect to have to wait for data. Second, you are copying the data one byte at a time which is not very efficient. Try something like:
    // Sender
    try {
        File localFile = new File("shared/"+fileName);
        OutputStream out = socket.getOutputStream();     
        InputStream fis = new FileInputStream(localFile);
        int length;
        byte[] buffer = new byte[4096];
        while((length = fis.read(buffer)) != -1)
         out.write(buffer, 0, length);
        fis.close();
        out.close();
    catch(Exception e){}
    // Receiver
    try {
        File downloadFile = new File("incoming/"+fileName);
        IntputStream ois = connectedSocket.getIntputStream();     
        OutputStream fos = new FileOutputStream(downloadFile);
        int length;
        byte[] buffer = new byte[4096];
        while((length = ois.read(buffer)) != -1)
         fos.write(buffer, 0, length);
        fos.close();
        ois.close();
    catch(Exception e){}

  • TCP Socket Adapter

    I want to use BPEL to integrate Oracle CRM with some banking software that validates bank sort codes and account numbers. The banking validation software listens for an input stream on a TCP socket.
    Can anyone tell me where I can find the technology socket adapter that are referenced on a number of Oracle presentations?
    I know I could write code in Java to achieved the same effect, but if there is an adapter that can do the job then that is preferable.

    I too am looking for this. I see that one of the posters above mentions an item provided by oracle, more details would be appreciated.
    In the mean time, I think the way to go is to write a POJO that sits on the the tcp port and gets into the ESB via a message queue, allowing it to "send an event" if you will.
    The scenario where you want to go outbound to tcp might be a bit trickier, if I use the POJO approach, then my code is outside of the ESB, since the ESB would end by dumping to a message queue, and my POJO would pick up from there.
    It would be really nice to have an Oracle component specificially for TCP.

  • How to send packet using tcp socket ?

    hi ,
    i want to using tcp socket to send data in ipv6 environment. but why the data transfer is less than ipv4 environment?
    socket = new Socket("2001:0238:0600::2", 1234);am i wrong ?

    bobby92 wrote:
    why the data transfer is less than ipv4 environment?What do you mean?
    >
    socket = new Socket("2001:0238:0600::2", 1234);am i wrong ?No idea, since I've no idea what you're asking.

  • TCP sockets on MIDP over GPRS

    Extending the CLDC socket.Protocol class I can make a TCP socket connection from a MIDlet. I'm hoping to market my application on GPRS networks, but I'm not sure that it supports TCP connections. I've read that TCP runs on circuit switching networks, and UDP on packet switching networks. I think GPRS is the latter. I need to maintain a constant, "connection-oriented" socket - i.e. TCP. Does anyone happen to know whether TCP/IP will function properly over GPRS? I realise this is why MIDP only implements HTTP and not raw sockets, but I thought it was worth asking anyway. Any help at all would be greatly appreciated.

    Hi Briggsd!
    I'm playing with some sockets.
    can you please help me?!
    J2ME uses only HTTP connections?
    and what are the sockets? what is the difference between CLDC socket and J2SE Socket?
    is there any other way to communicate with a Servlet?
    and very important..
    is there a difference if it's using GPRS or 3G?
    would the http connection work for all? and just the connection speed would change?
    help me!!

  • Audio over TCP Socket

    Hi,
    I need a sample code for transmit/receive a audio over TCP socket.. can anybody help me?

    You send and receive it in the same way as you handle any binary data.
    Kaj

  • Which load testing tool is appropriate for sending message to a tcp socket

    Hi,
    I am new to the testing world. I have developed a messaging application, where the client sends his requests on to the server program which opens a socket and listens for messages. Then all mesaging goes on. I want to load test my application. I have tested it with Apache's JMeter, besides that are there any other load testing tools.
    The clients need to send messages on a tcp socket. I really need this, please help me.
    Thanks,

    Dude,
    Write one!
    I test any servers I've written by hammering them by writing a multi-threaded test program to simulate client activity, namely an initial login and then whatever other activity the client would usually perform. Maybe in your case this would involve the sending of messages, the checking/reading of new messages and logging out.
    I usually get my timing statistics by simply capturing a start time and an end time (the difference being the m/s taken). ie: using java.util.Date.
    Run the test program from a single host to iron out any initial problems, but then be sure to run it from as many different hosts as you can get your mitts on!

  • Communication with database using TCP sockets connection

    Hi all,
    I am bit of a newbie when it comes to databases. In a project I realised over te passed few weeks, I communicated with an 11g database using an application I created with VS Express. It uses an ODBC connection. I now want to connect a PLC to the same database. These PLC's don't have the ability to install an ODBC client so I need something different.
    I am easily able to open a TCP socket on the PLC and send data from there. I would like to know if I can start a TCP sockets connection with our 11g server and send all queries directly. The other (already suggested) option would be to have the PLC connect to a PC that reads this information and hands it over to the ODBC connector, but that would mean I need an extra PC just to 'translate'.
    I have been searching these forums for socket, TCP and more and feel it is possible, but I need a good document as a reference to show/tell me how it's done.
    Thanks in advance,
    Marijn

    The TCP/IP interface to Oracle is undocumented (and hugely complex anyway). You'll need to use a higher layer iterface or setup your own infrastructure.
    We need more information about what is available to you inside the PLC.
    Can you use Java? If so, perhaps use thin JDBC?
    Can you sent HTTP requests? If so you could set up your own Web services to handle this.
    If you can only use C or C++, Oracle has interfaces there too.. it's called OCI (Oracle Call Interface) and thats as close to the networking layer as you can get.
    Finally if you can use .NET Oracle has a Fully Managed Oracle Data Provider for .NET that you could use.
    But if all you can do is super low level network access and none of the above then you will need to set up an intermediary as you mentioned.

  • Get phone number when open tcp socket

    I can get phone number and other info of phone when mobile connect to server by http on GPRS, but can I get phone number when connect by tcp socket?

    When you open a tcp connection by socket from mobile phone to IP server, you use ip end to end connectivty. In fact, when you use GPRS support on your mobile phone this one have a public IP address used to establish an IP connection to an other IP device.
    If you want to get the phone number, two solutions :
    1/ you transmit the phone number like a datastream on you socket. But it's a static solution, because you must enter the mobile number as a input (through a textfield form or somethink like that)
    2/You take the phone number in the memory of your mobile phone (Agenda). But it's so compicated because that's depend of type of mobile. The memory design is dedicated mobile by mobile.

  • Solaris IPC vs TCP sockets

    Hi. I'm not sure if this is the right forum for this question, so my apologies in advance if it's not (and I would appreciate being pointed to the right place).
    My question is about the speed and efficiency of using TCP sockets vs. other IPC mechanisms (e.g. message queues) to communicate between 2 processes on the same system. We currently use TCP sockets to send messages between 2 applications at a very high rate and are looking to improve performance and reduce CPU usage if we can. Both apps are on the same system and the sockets use TCP_NO_DELAY with application level buffering.
    Would we gain anything by using message queues or other IPC mechanisms? Any other suggestions for improving performance?
    Thanks very much in advance.
    spc

    Use IP if you ever expect that the applications would run in a
    distributed environment. It is fairly efficient on a single host
    via the loopback port.
    There are at least a dozen ways to do this. If we look at the
    database industry, they've largely chosen to use shared
    memory and semaphores. Shared memory is, naturally, very
    fast. But you need to communicate between processes to
    ensure consistency, which is where the semaphores come
    into play.
    In general, this is not an easy question to answer because
    there are two ends of the spectrum: lots of itty-bitty messages
    or big-honking messages. To optimize for one extreme leads
    you to become inefficient at the other. If you do a literature
    search you should find lots of papers written on the subject.
    -- richard

  • HttpConnection & TCP Sockets

    I wish to receive an httprequest on a tcpsocket. That is one midlet opens an httpconnection and the other midlet opens a tcp socket. Is it posiible for two way communication between them.
    If so how can the tcp socket read the data.

    Hi Briggsd!
    I'm playing with some sockets.
    can you please help me?!
    J2ME uses only HTTP connections?
    and what are the sockets? what is the difference between CLDC socket and J2SE Socket?
    is there any other way to communicate with a Servlet?
    and very important..
    is there a difference if it's using GPRS or 3G?
    would the http connection work for all? and just the connection speed would change?
    help me!!

  • Windows TCP Socket Buffer Hitting Plateau Too Early

    Note: This is a repost of a ServerFault Question edited over the course of a few days, originally here: http://serverfault.com/questions/608060/windows-tcp-window-scaling-hitting-plateau-too-early
    Scenario: We have a number of Windows clients regularly uploading large files (FTP/SVN/HTTP PUT/SCP) to Linux servers that are ~100-160ms away. We have 1Gbit/s synchronous bandwidth at the office and the servers are either AWS instances or physically hosted
    in US DCs.
    The initial report was that uploads to a new server instance were much slower than they could be. This bore out in testing and from multiple locations; clients were seeing stable 2-5Mbit/s to the host from their Windows systems.
    I broke out iperf
    -s on a an AWS instance and then from a Windows client in the office:
    iperf
    -c 1.2.3.4
    [ 5] local 10.169.40.14 port 5001 connected with 1.2.3.4 port 55185
    [ 5] 0.0-10.0 sec 6.55 MBytes 5.48 Mbits/sec
    iperf
    -w1M -c 1.2.3.4
    [ 4] local 10.169.40.14 port 5001 connected with 1.2.3.4 port 55239
    [ 4] 0.0-18.3 sec 196 MBytes 89.6 Mbits/sec
    The latter figure can vary significantly on subsequent tests, (Vagaries of AWS) but is usually between 70 and 130Mbit/s which is more than enough for our needs. Wiresharking the session, I can see:
    iperf
    -c Windows SYN - Window 64kb, Scale 1 - Linux SYN, ACK: Window 14kb, Scale: 9 (*512) 
    iperf
    -c -w1M Windows SYN - Windows 64kb, Scale 1 - Linux SYN, ACK: Window 14kb, Scale: 9
    Clearly the link can sustain this high throughput, but I have to explicity set the window size to make any use of it, which most real world applications won't let me do. The TCP handshakes use the same starting points in each case, but the forced one scales
    Conversely, from a Linux client on the same network a straight, iperf
    -c (using the system default 85kb) gives me:
    [ 5] local 10.169.40.14 port 5001 connected with 1.2.3.4 port 33263
    [ 5] 0.0-10.8 sec 142 MBytes 110 Mbits/sec
    Without any forcing, it scales as expected. This can't be something in the intervening hops or our local switches/routers and seems to affect Windows 7 and 8 clients alike. I've read lots of guides on auto-tuning, but these are typically about disabling scaling
    altogether to work around bad terrible home networking kit.
    Can anyone tell me what's happening here and give me a way of fixing it? (Preferably something I can stick in to the registry via GPO.)
    Notes
    The AWS Linux instance in question has the following kernel settings applied in sysctl.conf:
    net.core.rmem_max = 16777216
    net.core.wmem_max = 16777216
    net.core.rmem_default = 1048576
    net.core.wmem_default = 1048576
    net.ipv4.tcp_rmem = 4096 1048576 16777216
    net.ipv4.tcp_wmem = 4096 1048576 16777216
    I've used dd
    if=/dev/zero | nc redirecting to /dev/null at
    the server end to rule out iperfand
    remove any other possible bottlenecks, but the results are much the same. Tests with ncftp(Cygwin,
    Native Windows, Linux) scale in much the same way as the above iperf tests on their respective platforms.
    First fix attempts.
    Enabling CTCP - This makes no difference; window scaling is identical. (If I understand this correctly, this setting increases the rate at which the congestion window is enlarged rather than the maximum size it can reach)
    Enabling TCP timestamps. - No change here either.
    Nagle's algorithm - That makes sense and at least it means I can probably ignore that particular blips in the graph as any indication of the problem.
    pcap files: Zip file available here: https://www.dropbox.com/s/104qdysmk01lnf6/iperf-pcaps-10s-Win%2BLinux-2014-06-30.zip (Anonymised
    with bittwiste, extracts to ~150MB as there's one from each OS client for comparison)
    Second fix attempts.
    I've enabled ctcp and disabled chimney offloading: TCP Global Parameters
    Receive-Side Scaling State : enabled
    Chimney Offload State : disabled
    NetDMA State : enabled
    Direct Cache Acess (DCA) : disabled
    Receive Window Auto-Tuning Level : normal
    Add-On Congestion Control Provider : ctcp
    ECN Capability : disabled
    RFC 1323 Timestamps : enabled
    Initial RTO : 3000
    Non Sack Rtt Resiliency : disabled
    But sadly, no change in the throughput.
    I do have a cause/effect question here, though: The graphs are of the RWIN value set in the server's ACKs to the client. With Windows clients, am I right in thinking that Linux isn't scaling this value beyond that low point because the client's limited CWIN
    prevents even that buffer from being filled? Could there be some other reason that Linux is artificially limiting the RWIN?
    Note: I've tried turning on ECN for the hell of it; but no change, there.
    Third fix attempts.
    No change following disabling heuristics and RWIN autotuning. Have updated the Intel network drivers to the latest (12.10.28.0) with software that exposes functioanlity tweaks viadevice manager tabs. The card is an 82579V Chipset on-board NIC - (I'm going to
    do some more testing from clients with realtek or other vendors)
    Focusing on the NIC for a moment, I've tried the following (Mostly just ruling out unlikely culprits):
    Increase receive buffers to 2k from 256 and transmit buffers to 2k from 512 (Both now at maximum) - No change
    Disabled all IP/TCP/UDP checksum offloading. - No change.
    Disabled Large Send Offload - Nada.
    Turned off IPv6, QoS scheduling - Nowt.
    Further investigation
    Trying to eliminate the Linux server side, I started up a Server 2012R2 instance and repeated the tests using iperf (cygwin
    binary) and NTttcp.
    With iperf,
    I had to explicitly specify -w1m on both sides
    before the connection would scale beyond ~5Mbit/s. (Incidentally, I could be checked and the BDP of ~5Mbits at 91ms latency is almost precisely 64kb. Spot the limit...)
    The ntttcp binaries showed now such limitation. Using ntttcpr
    -m 1,0,1.2.3.5 on the server and ntttcp
    -s -m 1,0,1.2.3.5 -t 10 on the client, I can see much better throughput:
    Copyright Version 5.28
    Network activity progressing...
    Thread Time(s) Throughput(KB/s) Avg B / Compl
    ====== ======= ================ =============
    0 9.990 8155.355 65536.000
    ##### Totals: #####
    Bytes(MEG) realtime(s) Avg Frame Size Throughput(MB/s)
    ================ =========== ============== ================
    79.562500 10.001 1442.556 7.955
    Throughput(Buffers/s) Cycles/Byte Buffers
    ===================== =========== =============
    127.287 308.256 1273.000
    DPCs(count/s) Pkts(num/DPC) Intr(count/s) Pkts(num/intr)
    ============= ============= =============== ==============
    1868.713 0.785 9336.366 0.157
    Packets Sent Packets Received Retransmits Errors Avg. CPU %
    ============ ================ =========== ====== ==========
    57833 14664 0 0 9.476
    8MB/s puts it up at the levels I was getting with explicitly large windows in iperf.
    Oddly, though, 80MB in 1273 buffers = a 64kB buffer again. A further wireshark shows a good, variable RWIN coming back from the server (Scale factor 256) that the client seems to fulfil; so perhaps ntttcp is misreporting the send window.
    Further PCAP files have been provided, here:https://www.dropbox.com/s/dtlvy1vi46x75it/iperf%2Bntttcp%2Bftp-pcaps-2014-07-03.zip
    Two more iperfs,
    both from Windows to the same Linux server as before (1.2.3.4): One with a 128k Socket size and default 64k window (restricts to ~5Mbit/s again) and one with a 1MB send window and default 8kb socket size. (scales higher)
    One ntttcp trace
    from the same Windows client to a Server 2012R2 EC2 instance (1.2.3.5). here, the throughput scales well. Note: NTttcp does something odd on port 6001 before it opens the test connection. Not sure what's happening there.
    One FTP data trace, uploading 20MB of /dev/urandom to
    a near identical linux host (1.2.3.6) using Cygwin ncftp.
    Again the limit is there. The pattern is much the same using Windows Filezilla.
    Changing the iperf buffer
    length does make the expected difference to the time sequence graph (much more vertical sections), but the actual throughput is unchanged.
    So we have a final question through all of this: Where is this limitation creeping in? If we simply have user-space software not written to take advantage of Long Fat Networks, can anything be done in the OS to improve the situation?

    Hi,
    Thanks for posting in Microsoft TechNet forums.
    I will try to involve someone familiar with this topic to further look at this issue. There might be some time delay. Appreciate your patience.
    Thank you for your understanding and support.
    Kate Li
    TechNet Community Support

  • Problem about TCP Socket

    I have made a File Transfer program using TCP.
    But I find a strange problem.
    The socket will be closed after sending a file.....
    Is my code wrong or the socket is this?
    Should I upload my code??

    my new version of code...
    but there are still some problems
    1.After sending file and without closing the program, the file is still occupied by the program
    2.The received file is still different from the original...
    btw, I still don't know how to put the bos outside the loop...
    I need to use the filename as a parameter of constructor of bos
      public void sendFile(final String file) {
            new Thread(new Runnable() {
                public void run() {
                    try {
                        DataOutputStream dis = new DataOutputStream(socket.getOutputStream());
                        dis.writeUTF(new File(file).getName());
                        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(new File(file)));
                        BufferedOutputStream bos = new BufferedOutputStream(socket.getOutputStream());
                        byte[] buffer = new byte[8192];
                        int count = 0;
                        while ((count = bis.read(buffer)) != -1) {
                            bos.write(buffer, 0, count);
                            System.out.write(buffer,0,count);                       
                        System.out.println("FINISHING SENDING FILES!");
                        bos.flush();
                        bis.close();                   
                    } catch (Exception e) {
                        e.printStackTrace();
            }).start();
        public void receiveFile() {
            new Thread(new Runnable() {
                public void run() {
                    try {
                        BufferedInputStream bis = new BufferedInputStream(socket.getInputStream());
                        BufferedOutputStream bos;
                        DataInputStream dis =new DataInputStream( socket.getInputStream());
                        while (true) {
                            String fileName = dis.readUTF();
                            bos = new BufferedOutputStream(new FileOutputStream(new File(fileName)));
                            byte[] buffer = new byte[8192];
                            int count = 0;
                            while ((count = bis.read(buffer)) != -1) {
                                bos.write(buffer, 0, count);
                                System.out.write(buffer,0,count);                          
                            bos.flush();
                            bos.close();                    
                    } catch (Exception e) {
                        e.printStackTrace();
            }).start();
        }

  • TCP socket I/O from the kernel

    We've been working on extending our filesystem support from UDP to TCP,
    and have run into an apparent roadblock. We'd like to know whether
    Sun is aware of the problem that we're seeing, and if so, if there
    is something else we should be doing to avoid it.
    We've been using the "sockfs" module to create sockets [where
    sockfs_xxx is found using modlookup("sockfs", "xxx")]:
    avp = sockfs_solookup(AF_INET, SOCK_STREAM, 0, "/dev/tcp", &rc);
    sop = sockfs_socreate(avp, AF_INET, SOCK_STREAM, 0,
    SOV_DEFAULT, NULL, &rc);
    binding, and setting some socket ops:
    sockfs_sobind(sop, (struct sockaddr *)&client_addr,
    sizeof(client_addr), 0, 0);
    sockfs_sosetsockopt(sop, SOL_SOCKET, ... );
    and connecting:
    sockfs_soconnect(sop, (struct sockaddr *)&server_addr,
    sizeof(server_addr), 0, 0);
    We're able to send data successfully with:
    sockfs_sosendmsg(sop, &nmsg, &uio);
    where uio.uio_segflg = UIO_SYSSPACE;
    But when we try to receive with a similar
    sockfs_sorcvmsg(sop, &nmsg, &uio);
    we regularly receive EFAULT errors.
    [This same sequence works fine for both send and receive if we use
    /dev/udp instead.]
    As we trace through the call, we see that TCP uses a special UIO
    function (uioipcopyout) that simply returns EFAULT for any
    UIO_SYSSPACE move. The use of this function appears to be driven by
    queue settings (STRUIOT_IP) in the TCP stream queue initializers.
    So, our questions are:
    Is there a way to override this behavior (safely)?
    Should we be using another interface to do socket I/O
    from the kernel? (At first glance, that wouldn't help
    us here, as this deeply rooted in the TCP implementation.)
    Are there any code examples (published or otherwise)
    that would help us here?
    Thanks for any help you can offer us!

    you can do this in Java 5.0 using jline (must be around version 0.9.91) it must be running on linux/unix/mac though. i think in the future jline may support windowsTerminal also. however with java 6.0 you may wonder what's the point
    public static String readPassword(String prompt) {
    try {
    Terminal t = Terminal.getTerminal();
    if(t instanceof jline.UnixTerminal){
    UnixTerminal ut = (UnixTerminal) t;
    ConsoleReader reader = new ConsoleReader();
    //ConsoleReaderInputStream cris = new ConsoleReaderInputStream(reader);
    Character mask = new Character((char) 0);
    //reader.setEchoCharacter(new Character('0'));
    String line = null;
    do {
    line = reader.readLine(prompt,mask) ;
    if (line != null){
    //reader.setEchoCharacter(null);
    reader.flushConsole();
    ut.restoreTerminal();
    return line;
    } while(line != null && line.length() > 0);
    } catch (Exception e){}
    return null;
    }

Maybe you are looking for

  • How to: Resize a rows height in a table using acrobat 9 pro?

    I'm working on a government grant, with many tables that need to be resized in order to fit the required information. Can anyone help me?

  • Inserting items into List on a JSP

    I want to insert new items into a multiple select list from database on selecting an item from an existing list in a JSP. I am not sure how to do this. thanks

  • Firefox shows wrong page when application opens a new window

    Only fails since V4.0.0 installed. pages that open a new window using window.open(url) sometimes produce a page from cache instead of the page to be loaded. This seems erratic. Often, failure starts after a popup window loads and is closed, then atte

  • Problem inserting an image

    I have a div tag  that's 100x100 px.  I have an image I created in photoshop that is 100x100 pixels, but for some reason when I insert the image into the div tag it extends beyond the 100x100 and doesn't insert exactly into the div tag.  Any suggesti

  • New Nvidia 196 WHQL driver

    I see 195.81 Beta is now superceded by 196.21 WHQL at a whopping 149MB (for the UK language). Cheers, Neale Insanity is hereditary, you get it from your children