SO_REUSEADDR socket option

I'm working on a Java FTP server implementation (JDK 1.4) and one of the requirements is using local port 20 for data connections (in active mode). Unfortunately, once the first socket is connected, I'm not able to open another one, I can't reuse the same local port (20).
My understanding is that TCP does allow reusing of the same local port as long as the SO_REUSEADDR option is set and the complete association is unique (the 5-tuple association). The setReuseAddress method of the socket class seems to imply that you can only reuse the local port if the socket in a TIME-WAIT mode but not if it is already bound.
"Enabling SO_REUSEADDR prior to binding the socket using bind(SocketAddress) allows the socket to be bound even though a previous connection is in a timeout state"...
"The behaviour when SO_REUSEADDR is enabled or disabled after a socket is bound (See isBound()) is not defined."
http://java.sun.com/j2se/1.4.1/docs/api/java/net/Socket.html
Can someone PLEASE shed some light on this topic for me? Is it possible to have sockets reuse the local port as long as the remote port is different (even if another socket is already bound)?
socket1 (tcp, clienthost, 5000, serverhost, 20)
socket2 (tcp, clienthost, 5001, serverhost, 21)
If so, how?
Thanks,

Sorry, I've accidentally wrote 21 for the local port on socket2. It should read 20.
socket1 (tcp, clienthost, 5000, serverhost, 20)
socket2 (tcp, clienthost, 5001, serverhost, 20)
socketN (tcp, anyClientHost, anyClientPort, serverhost, 20)

Similar Messages

  • How to implement custom socket option.

    In our application we use DatagramSocket. We are able to set the standard socket options that are implemented in SocketOption interface by using the setter methods available in DatagramSocket. We need to set a custom (non-standard) socket option in the DatagramSocket created.
    Any help on how to do this?

    Hi,
    this document in addition
    http://www.oracle.com/technology/products/jdev/howtos/10g/jaassec/index.htm
    has a list of LoginModules, one that authenticates against physical database users
    Frank

  • Socket options to support hand off across wireless networks

    Hello,
    I'm developing an application client which connects to a server and is meant to run on PCs. I want to make sure that my client application doesn't disconnect when the user moves from one network to another network (one cafe to another cafe).
    Is there any socket option to support this kind of client application requirements?

    EJP wrote:
    You had better take this up with Tim ( http://www.w3.org/People/Berners-Lee/ ) and the co-inventors if the Internet protocols.
    This nonsense is frequently encountered in newspapers and magazines, but I'm surprised to see it repeated here. Tim Berners-Lee is not an inventor or co-inventor of any Internet protocols except HTTP, which follows exactly the same principles as FTP, SMTP, etc: very tolerant line-oriented headers, and MIME-encoded data. These principles, not to mention the Internet protocols proper like IP, ICMP, UDP, TCP, etc., were invented by people like Vincent Cerf, decades before Berners-Lee had anything to do with it. Have a look at the authors and the dates on the RFCs. Berners-Lee is also credited with 'inventing' HTML which is a mild reworking of IBM SGML.:-) I stand corrected.

  • What this??? java.io.IOException: Couldn't get socket option ???

    I have
    ===================================================
    public static UDPDatagramConnection datagramConnection =(UDPDatagramConnection)Connector.open("datagram://:1234");
    ===================================================
    and code
    ===================================================
    try {
    Datagram sendDatagram = datagramConnection.newDatagram
    msg, msg.length, "datagram://111.222.333.444:1234");
    datagramConnection.send(sendDatagram);
    } catch (IOException ioe) {
    System.out.println(ioe.toString());
    ===================================================
    wrote in 2 differet classes and call 2 different threads. Each thread send its own variable "msg ". After some time I have "java.io.IOException: Couldn't get socket option".
    Have you any ideas about this?
    Message was edited by:
    Lac_equinu

    you're attempting to call "runbatch T9Batch -b BTNORM -d A", which has the executable "runbatch", and 5 arguments. Runtime.exec(String []) is expecting an array of the command and it's arguments. So I think you need to pass it an array like:
    cmd[0] = runbatch
    cmd[1] = T9Batch
    cmd[2] = -b
    cmd[3] = BTNORM
    cmd[4] = -d
    cmd[5] = A

  • Setting socket options server-side: when?

    Hi!
    I'm trying to implement a iperf ( http://dast.nlanr.net/Projects/Iperf/ ) -like bandwidth measurement tool in java, and I need to be able to set different socket options (window size, TOS byte etc.)
    My question would be, when should I be setting these options on the server-side? Should I set them for the ServerSocket (whatever's applicable there- not much), or should I try setting them on the socket returned by accept() ?

    Yes, but my point is that you can't set TOS in 1.4
    regardless of where is should be set, so the point is
    moot. And although you can do that in 1.5 that might
    not meet your goals (and given that 1.5 is in beta and
    that the feature is new, it might not work at all.)
    And 1.5 might not do the other stuff that you want
    either.That's strange, as I thought this one should do just that:
    http://java.sun.com/j2se/1.4.2/docs/api/java/net/Socket.html#setTrafficClass(int)
    Even stranger, as I was actually able to set the TOS byte on outgouing packets, using 1.4.2 (Although I'm aware, that it does depend on the underlying implementation, so it's not certain, that it will be respected)
    Right now I'm trying to figure out, why it's not working on my Gentoo Linux system - tryed it with three different JREs, but still nothing.
    I was able to set the TOS byte of outgouing packets on a RedHat7.3, and on several Win2k, and WinXP hosts (after working a bit on their registry ... ).

  • Socket options - redux

    If you go look at the documentation for setsockopt under Windows CE 5.0, you will read this:
    The following list shows BSD options that are not supported for setsockopt .
    SO_ACCEPTCONN
    SO_RCVLOWAT
    SO_RCVTIMEO
    SO_SNDLOWAT
    SO_SNDTIMEO
    SO_TYPE
    Today I did some poking around as our next project will be on Windows Compact Embedded 7.  I've been developing and maintaining products based on CE 4.1 and 5.0, so I was hoping for an update.  Now I'm reading for Windows Compact 2013, and the same
    options are not supported. If anything, Microsoft is consistent. <-- for the humor impaired.  Since 2013 doesn't support the above options,
    I'm sure Compact 7 won't either.
    Anyone out there know as to why Microsoft would not / never support the full BSD socket implementation? I can work around it (it's coyote ugly), but I'm just curious.
    Thanks
    cg
           

    Hi cg11,
    Personally I don't think the blog feedback is useful, the latest update time is around 6 years ago.
    However I'm not able to comment why the API designed like this, probably some features are not opened due to some security thinking, if you need feedback you can consider
    FAQs About Submitting Feedback.
    Thanks for your understanding.
    --James
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • ServerSocket not closing...JRockit Bug?

    The following sample program does not behave as expected with JRockit, but works
    fine with Sun JVM.
    import java.net.*;
    import java.io.*;
    public class SocketTest {
    static ServerSocket soc = null;
    public static void main(String [] args) throws Exception {
    int port = Integer.parseInt(args[0]);
    soc = new ServerSocket(port);
    Runtime.getRuntime().exec("notepad");
    soc.close();
    System.exit(0);
    When this program is run with JRockit JVM, till I close the notepad, the server
    socket is not getting freed even though the parent process has exited!! But, with
    sun jvm as soon as the parent process exits, the port does get freed.
    Isn't this a BUG?
    Rgds,
    Thiru

    I am able to reproduce the problem in JRockit 8.1. I can see that the socket
    is not getting released till the notepad is closed by using netstat.
    I am not sure about the version that you are using. There is no 1.4
    compatible version in JRockit 70SP4 (its only 1.3 compatible). If you want
    to use 1.4 compatible, you need to upgrade to 8.1
    This issue is fixed in 81SP1 (CR102658). Please download 81SP1 (1.4.1)and
    try.
    http://commerce.bea.com/showallversions.jsp?family=WLJR
    Sathish Santhanam
    Developer Relations Engineer
    BEA Support
    "Thirumalesh C" <[email protected]> wrote in message
    news:[email protected]...
    >
    Hi,
    I am testing whether the socket is freed up or not using a tool (nettool)which
    >
    allows me tunnel one port to another.
    In fact after running the test program, before closing notepad, if you runanother
    program
    that tries to bind to the same socket, it fails.
    Rgds,
    Thiru
    "Thirumalesh C" <[email protected]> wrote:
    Hi,
    Thanks for the reply.
    I had tried that too, it did not work.
    Below is the code.
    import java.net.*;
    import java.io.*;
    public class SocketTest {
    static ServerSocket soc = null;
    public static void main(String [] args) throws Exception {
    int port = Integer.parseInt(args[0]);
    soc = new ServerSocket();
    InetSocketAddress isoc = new InetSocketAddress("mymachine",port);
    soc.setReuseAddress(true);
    soc.bind(isoc);
    Runtime.getRuntime().exec("notepad");
    soc.close();
    System.exit(0);
    Even with this, I have the same problem.
    I am using JRockit 7.0 (1.4.0) on Windows 2000 platform with SP4.
    Please note that the same program works fine with Sun JVM 1.4.1
    Rgds,
    Thiru
    "Cecilia Borg" <[email protected]> wrote:
    Thiru,
    I'm not sure what you mean by "the socket is not getting freed", can
    you
    describe in more detail how you did that check? On what platform and
    with
    which version of JRockit do you experience this?
    Could you have experienced problems the timeout state that with your
    ServerSocket connection? In that case, you can try to use the
    setReuseAddress-method in the ServerSocket class.
    In the api for ServerSocket:setReuseAddress in JDK 1.4.1:
    setReuseAddress
    public void setReuseAddress(boolean on)
    throws SocketExceptionEnable/disable the
    SO_REUSEADDR
    socket option.
    When a TCP connection is closed the connection may remain in a timeout
    state
    for a period of time after the connection is closed (typically known
    as the
    TIME_WAIT state or 2MSL wait state). For applications using a well known
    socket address or port it may not be possible to bind a socket to the
    required SocketAddress if there is a connection in the timeout state
    involving the socket address or port.
    Enabling SO_REUSEADDR prior to binding the socket usingbind(SocketAddress)
    allows the socket to be bound even though a previous connection is in
    a
    timeout state
    Kind regards, Cecilia Borg
    BEA WebLogic JRockit Customer Centric Engineering

  • Able to bind to the same port on twice with  setSocketOptionReuseAddress

    Hi,
    I am not sure wether it is bug in API or lack in understanding.
    I have a server , using Java networking API and I have set "setSocketOptionReuseAddress(true)" for "java.net.ServerSocket". Now I am able to start more than one instances of server with same port and IP.
    If I set "setSocketOptionReuseAddress" to false. second instance won't start an throws 'Address in user : bind exception".
    setSocketOptionReuseAddress is supposed to help only in socket "TIME_WAIT" situation, why is bind getting effected by this?

    I assume the original poster is on Windows in which case the SO_REUSEADDR socket option has different semantics for streams socket compared to other platforms. As the poster says, it allows multiple servers to bind to the same socket. Assuming this is a ServerSocket then the simplest solution would be not use setReuseAddress -- ie: leave it as its default value and everything should be fine. On Windows you can re-bind when a previous connection is in TIME_WAIT. On other platforms (Solaris/Linux anyway), the SO_REUSEADDR option is enabled by default for ServerSockets so the server can be restarted even if there is a connection in TIME_WAIT.

  • Sockets, multicast/broadcast, UDP, TCP, SO_REUSEADDR, SO_REUSEPORT and SO_EXCLUSIVEADDRUSE

    EDIT: the topic was moved to https://social.msdn.microsoft.com/Forums/vstudio/en-US/6b0fbcbc-1139-4d7a-a62a-a5b16a6e0229/sockets-multicastbroadcast-udp-tcp-soreuseaddr-soreuseport-and-soexclusiveaddruse?forum=wcf .
    Hello,
    in the project Dao (https://github.com/daokoder/dao) we got stuck upon a problem with a wrapper interface for bind(), which should be multiplatform (work on all Windows versions from XP higher and also on BSDs and also other POSIX systems) and offer the
    following two options:
    1) A safe bind of one socket, one address (specific or wildcard) and one port such that no other process (disregarding the user the process runs under and disregarding user privileges) could be successful with a call to bind() on the same socket with the
    same address and the same port.
    2) A bind with allowing multicast/broadcast, reuse of address, port and all these disregarding the state of the socket (e.g. TIME_WAIT) and disregarding the type of connection (UDP, TCP). In other words, the behavior should be the same a the behavior of
    BSD sockets in all cases and under all conditions.
    The main differences between BSD and Windows are conveniently described on http://stackoverflow.com/questions/14388706/socket-options-so-reuseaddr-and-so-reuseport-how-do-they-differ-do-they-mean-t . According to that, one would say that a solution:
    1) For BSD "0" and for Windows "SO_EXCLUSIVEADDRUSE"
    2) For BSD "SO_REUSEPORT | SO_REUSEADDR" and for Windows "SO_REUSEADDR"
    is enough. But it's not true. For example due to Enhanced Socket Security and their behavior described in the table http://msdn.microsoft.com/en-us/library/windows/desktop/ms740621(v=vs.85).aspx (after first call to bind() with wildcard address and SO_REUSEADDR
    set, a second call to bind() with non-wildcard address and SO_REUSEADDR set will fail with error WSAEACCES).
    A solution might be to gather all the needed information (like user id, if there are any processes using that particular socket and if a call to connect() was already issued in case of TCP) and according to this information use the right mix of options SO_REUSEADDR,
    SO_EXCLUSIVEADDRUSE and others if needed. We didn't find though enough documentation about where to get all the needed information. Note that this solution would need an atomic query on socket (for all the information) in conjunction with a call to bind().
    Another solution could be to call bind() with different flags and decide upon the return error codes. This is though a nasty hack we would like to avoid.
    The question for you is, if you happen to know about any better solution than the ones mentioned above. There is a public discussion about this problem starting with comment https://github.com/daokoder/dao/issues/243#issuecomment-60434078 .
    Thank you in advance!

    Hi dao_lang_rulezz,
    Thanks for posting in the TechNet Forum.
    As my point of viewer, this requirement is related to program developing issue.
    This forum is related to Windows 8.1 Client.
    To receive better support, it is recommend to ask in corresponding developing forum.
    Best regards,
    Fangzhou CHEN
    Fangzhou CHEN
    TechNet Community Support

  • Problem in file and socket fd

    Hi
    I am using TCP sockets for communication.I create a server which blocks on the accept method to listen for new connections.
    The problem is that if I open a file descriptor in the program ,then the server does not block on accept method but instead it reads garbage from the socket.
    What could be the possible problem.??
    Thanks

    hi Here I am sending you a piece of code thaat simply starts a server and opens a file . When I run this ther server does not wait .And if I comment out the line which openss the file it works fine .
    <pre>
    #include <stdio.h>
    #include <strings.h>
    #include <unistd.h>
    #include <sys/types.h>
    #include <sys/wait.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <netinet/tcp.h>
    #include <netdb.h>
    #include <sys/uio.h>
    #include <arpa/inet.h>
    #include <errno.h>
    #include <ctype.h>
    #include <signal.h>
    #include <fcntl.h>
    #include <time.h>
    #include <sys/timeb.h>
    #include <stdlib.h>
    #include <stropts.h>
    #include <sys/filio.h>
    #include <iostream.h>
    #include <pthread.h>
    #include <plot.h>
    #define PORT 8888
    #define BACKLOG 10;
    int main()
    int listenfd ,connfd;
    //** if I comment this line server works fine
    int fd = open("file",O_RDWR,777);
    socklen_t clientlen;
    struct sockaddr_in clientaddr;
    struct sockaddr_in serveraddr;
    listenfd = socket(AF_INET,SOCK_STREAM,0);
    serveraddr.sin_family = AF_INET;
    serveraddr.sin_addr.s_addr = htonl(INADDR_ANY);
    serveraddr.sin_port = htons(8888);
    bzero(&(serveraddr.sin_zero), 8);
    int n=1;
    if (setsockopt (listenfd, SOL_SOCKET, SO_REUSEADDR, (char *)&n, sizeof (n)) <0)
    fprintf(stdout,"Error: socket option\n");
    close (listenfd);
    shutdown(listenfd,2);
    bind (listenfd,(sockaddr*) &serveraddr,sizeof(serveraddr));
    listen(listenfd,10);
    //*** Server Started
    printf("Server listening on port 8888 \n");
    connfd = accept(listenfd, (sockaddr*)&clientaddr,&clientlen);
    printf("Connected accepted \n");
    return 0;
    </pre>
    Thanks

  • [SOLVED]GPG no longer supports --no-use-standard-socket?

    I've used an SD card for where I store my gnupghome for a long time. I have delegated subkeys and all the configuration for them there. It's mounted to /mnt/keys on vfat. These cards use a FAT file system as I use these keys on multiple operating systems.
    GPG with release 2.1 has removed the 'standard socket' options, which means now if your gnupg home is on any file system that can't create socket files (see: FAT), gpg-agent can no longer run. Ironically, this is also the release that *removes* all support for running gpg without an agent!
    I'm disappointed this was not considered news for arch, I even wrote a small silly wrapper just for forcing me to read front page stories! (http://github.com/codemac/yosumiru)
    The GPG news page had the following:
    With GnuPG 2.1 the need of GPG_AGENT_INFO has been completely removed and the variable is ignored. Instead a fixed Unix domain socket named S.gpg-agent in the GnuPG home directory (by default ~/.gnupg) is used. The agent is also started on demand by all tools requiring services from the agent.
    Any thoughts on how I can keep my gnupg on a FAT filesystem and still run the agent? I'm feeling pretty hosed right now, and am pretty confused why this feature was removed from gpg agent, as this would be as simple as keeping the old functionality, but maybe forcing the --no-use-standard-socket option to be in gpg.conf
    Last edited by codemac (2014-12-02 18:43:06)

    codemac wrote:I've used an SD card for where I store my gnupghome for a long time. I have delegated subkeys and all the configuration for them there. It's mounted to /mnt/keys on vfat. These cards use a FAT file system as I use these keys on multiple operating systems.
    That's exactly what I used to do as well: mount a USB key read-only and run gpg --homedir /path/to/usb.
    codemac wrote:
    GPG with release 2.1 has removed the 'standard socket' options, which means now if your gnupg home is on any file system that can't create socket files (see: FAT), gpg-agent can no longer run. Ironically, this is also the release that *removes* all support for running gpg without an agent!
    I'm disappointed this was not considered news for arch, I even wrote a small silly wrapper just for forcing me to read front page stories! (http://github.com/codemac/yosumiru)
    The GPG news page had the following:
    With GnuPG 2.1 the need of GPG_AGENT_INFO has been completely removed and the variable is ignored. Instead a fixed Unix domain socket named S.gpg-agent in the GnuPG home directory (by default ~/.gnupg) is used. The agent is also started on demand by all tools requiring services from the agent.
    Any thoughts on how I can keep my gnupg on a FAT filesystem and still run the agent? I'm feeling pretty hosed right now, and am pretty confused why this feature was removed from gpg agent, as this would be as simple as keeping the old functionality, but maybe forcing the --no-use-standard-socket option to be in gpg.conf
    I don't understand why you insist on using --no-use-standard-socket...
    Some background: traditionally gpg-agent is started by a DE (e.g. xfce4-session starts it). This is useful because gpg-agent also manages ssh keys. However, this is not required anymore because agents are started on-demand and multiple agents can run concurrently.
    Now, if you didn't have a vFAT FS, all is good as you call gpg --homedir because it will invoke gpg-agent with the correct --homedir flag.
    So, all you need to do now is to rsync your gnupg dir on the SD card to some temp dir, e.g. /dev/shm/gnupg and use this dir as an argument to --homedir, and don't care about the agent at all.

  • Error when calling getLocalSocketAddress() on for a newly created socket

    Hello,
    I have an issue when using JVM 1.5.0.12 on HP-UX (IA64N):
    java.lang.Error: java.net.SocketException: Bad file number (errno:9)
         at sun.nio.ch.Net.localAddress(Net.java:123)
         at sun.nio.ch.SocketChannelImpl.localAddress(SocketChannelImpl.java:394)
         at sun.nio.ch.SocketAdaptor.getLocalAddress(SocketAdaptor.java:147)
         at java.net.Socket.getLocalSocketAddress(Socket.java:708)
    I get this error when I accept a connection from a remote peer and I try to call getLocalSocketAddress() method on the new accepted socket connection object.
    Does anyone have an idea about the cause for this error?
    I also get 2 other errors but in different places in the code:
    1/ java.io.IOException: No buffer space available (errno:233)
         at sun.nio.ch.ServerSocketChannelImpl.accept0(Native Method)
         at sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.java:145)
    This one I get when my server socket accepts a connection. But even if the connection is accepted succesfully, I might get the "java.lang.Error: java.net.SocketException: Bad file number (errno:9)" when trying to call getLocalSocketAddress()
    2/ Once I accept the new connection I call "socketChannel.socket().setTcpNoDelay(true)" but sometimes this fails with a SocketException: Invalid argument (errno:22).
    Al the 3 errors are manifesting sporadically and I cannot find the cause.

    Hello,
    Thanks for your quick response!
    We actually do something like this:
    // NIO engine build around a Selector for asynchronous IO developpement.
    public class NIOCore implements Runnable {
    private final Selector selector;
    private final Set<SelectableChannelListener> channels = new HashSet<SelectableChannelListener>();
    public void run() {
    for (final Iterator<SelectionKey> i = selector.selectedKeys().iterator(); i.hasNext();) {
    final SelectionKey selectionKey = i.next();
    i.remove();
    final SelectableChannelListener selectableChannelListener = (SelectableChannelListener) selectionKey.attachment();
    if (!selectionKey.isValid()) {
    continue;
    // Check what event is available and deal with it
    if (selectionKey.isAcceptable()) {
    if (log.isTraceEnabled()) {
    log.debug("Processing ACCEPT event for listener: " + selectableChannelListener);
    try {
    selectableChannelListener.acceptEvent();
    } catch (final Throwable t) {
    log.error("Error on ACCEPT event for listener " + selectableChannelListener, t);
    selectableChannelListener.close();
    As you ca see, we use to do a callback on our SelectableChannelListener objects. In our case the SelectableChannelListener object that actually propagates the JVM Error is this one:
    public final class Acceptor extends SelectableChannelListener {
    protected NIOCore core;
    public void acceptEvent() {
    SocketChannel socketChannel = serverSocketChannel.accept();
    if (socketChannel == null) {
    throw new NIOCoreException("No incoming connection to accept");
    // Socket options
    if (params.getSocketBufferSize() > 0) {
    socketChannel.socket().setSendBufferSize(params.getSocketBufferSize());
    try {
    socketChannel.socket().setTcpNoDelay(true);
    } catch (SocketException ex) {
    if (log.isDebugEnabled() || log.isTraceEnabled())
    log.warn(logPrefix + "could not set TCP_NODELAY socket option.You may experience performance loss", ex);
    else
    log.warn(logPrefix + "could not set TCP_NODELAY socket option. You may experience performance loss. Cause : " + ex.getMessage());
    // later if the connection is accepted succesfully this line is executed
    SocketAddress localAddress = socketChannel.socket().getLocalSocketAddress();
    @Override
    public void close() {
    core.unregister(this);
    try {
    selectableChannel.close();
    } catch (final IOException e) {
    // Ignore
    NIOPortManager.getInstance().setListenBindSapState(getBoundSAP(), true);
    So bassically when we call selectableChannelListener.close() we indeed close the ServerSocketChannel channel, but we also unregister the Acceptor observer object from NIOCore in order to free memory and set the SAP as available.
    The problem is that we cannot reproduce this issue (it reproduces only on our customers environment) and I consider rather risky to remove the selectableChannelListener.close() call.
    Actually I would catch the Error and package it in an internal runtime exception:
    SocketAddress localAddress = null;
    try {
    localAddress = socketChannel.socket().getLocalSocketAddress();
    catch (Throwable t) {
    throw new MyRunntimeException(t);
    And then to catch this new runtime exception in NIOCore class when this call is made:
    try {
    selectableChannelListener.acceptEvent();
    } catch (final MyRunntimeException e) {
    log.debug("JVM error occured!");
    } catch (final Throwable t) {
    log.error("Error on ACCEPT event for listener " + selectableChannelListener, t);
    selectableChannelListener.close();
    I know this is silly but at least we can use it as a temporary workaround until these JVM issues are fixed.
    Also since socketChannel.socket().getLocalSocketAddress() API call only throws that specific error from time to time, we could implement a retry mechanism. What I mean is to call getLocalSocketAddress() in a while loop and if the call fails with Error just continue to retry...we could provide 3 retries for example. If on the 3 ^rd^ retry the call also fails, just let it be failed and treat it in normal way.
    Best regards,
    Alex

  • Raw sockets with IP headers in mac osx

    I am trying to send IP packets through a raw socket (SOCK_RAW) on my mac (osx 10.6), and always get an "Invalid Argument" error. I have tried with IPPROTO_RAW, IPPROTO_UDP, and IPPROTO_DIVERT (which should also send raw packets). When using _RAW or _UDP, I also set the socket option for including ip headers with setsockopt(.., IP_HDRINCL, ..). Has anyone successfully sent IP packets with a raw socket on a mac that includes IP headers? Any example code I can use as a reference? Thanks!

    Well, in case anyone ever has the same issue, the only way I was able to inject packets back with my own IP headers was by writing to a bpf socket, which is not the prettiest way, but works. I am still interested in seeing IP_HDRINCL work on a raw socket, so if anyone has an example that works, please post!

  • Reading / Writing files using Sockets

    Hi there guys,
    I am fairly new to this forum. I have been having a problem for the past three days. I am implementing a client/server implementation using Sockets which is a submodule of a project I am working on. What I want is that a files content are read and transferred over the network to the server that writes it down to a different file .
    What the code presently does is :
    <<<<Client Code >>>>
    It reads a file input.txt and sends the content over the network to the server.
    <<<< Server Code >>>
    It reads the incoming data from the client and writes the data out to a file called output.txt
    What I want now is that the server should read the file output.txt and send the contents to the client which reads it and then writes it down as a new file called serverouput.txt . After that I want to compare and see of the size of input.txt and serveroutput.txt . If both are same that means that data has been written reliably to the server.
    I have been trying to implement it for a long time and nothing seems to work out. I am posting the code for both client and server below. Any help in finalising things would be really appreciated.
    CLIENT CODE
    import java.awt.Color;
    import java.awt.BorderLayout;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.Date;
    import java.io.*;
    import java.net.*;
    class sc {
    static final int PORT = 4444;          //Change this to the relevant port
    static final String HOST = "127.0.0.1";
         //Change this to the relevant HOST,
    //(where Server.java is running)
    public static void main(String args[]) {
    try {
    System.out.print("Sending data...\n");
    Socket skt = new Socket(HOST, PORT);
                   // Set the socket option just in case server stalls
    skt.setSoTimeout ( 2000 );
                   skt.setSoKeepAlive(true);
    //Create a file input stream and a buffered input stream.
    FileInputStream fis = new FileInputStream("input.txt");
    BufferedInputStream in = new BufferedInputStream(fis);
    BufferedOutputStream out = new BufferedOutputStream( skt.getOutputStream() );
    //Read, and write the file to the socket
    int i;
    while ((i = in.read()) != -1) {
    out.write(i);
    //System.out.println(i);
                   // Enable SO_KEEPALIVE
    out.flush();
    out.close();
    in.close();
    skt.close();
    catch( Exception e ) {
    System.out.print("Error! It didn't work! " + e + "\n");
              catch( IOException e ) {
    System.out.print("Error! It didn't work! " + e + "\n");
    SERVER CODE
    import java.awt.Color;
    import java.awt.BorderLayout;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.Date;
    import java.io.*;
    import java.net.*;
    class ClientWorker implements Runnable {
    private Socket client;
    ClientWorker(Socket client) {
    this.client = client;
    public void run(){
    try      {
    FileOutputStream fos = new FileOutputStream("output.txt");
    BufferedOutputStream out = new BufferedOutputStream(fos);
    BufferedInputStream in = new BufferedInputStream( client.getInputStream() );
    //Read, and write the file to the socket
    int i;
    while ((i = in.read()) != -1) {
    out.write(i);
    //System.out.println(i);
    System.out.println("Receiving data...");
    out.flush();
    in.close();
    out.close();
    client.close();
    // srvr.close();
    System.out.println("Transfer complete.");
    catch(Exception e) {
    System.out.print("Error! It didn't work! " + e + "\n");
    class ss1 {
    ServerSocket server = null;
    ss1(){ //Begin Constructor
    } //End Constructor
    public void listenSocket(){
    try{
    server = new ServerSocket(4444);
    } catch (IOException e) {
    System.out.println("Could not listen on port 4444");
    System.exit(-1);
    while(true){
    ClientWorker w;
    try{
    w = new ClientWorker(server.accept());
    Thread t = new Thread(w);
    t.start();
    } catch (IOException e) {
    System.out.println("Accept failed: 4444");
    System.exit(-1);
    protected void finalize(){
    //Objects created in run method are finalized when
    //program terminates and thread exits
    try{
    server.close();
    } catch (IOException e) {
    System.out.println("Could not close socket");
    System.exit(-1);
    public static void main(String[] args){
    ss1 frame = new ss1();
         frame.listenSocket();
    }

    ............................................. After that I want to
    compare and see of the size of input.txt and
    serveroutput.txt . If both are same that means that
    data has been written reliably to the server.You don't need to do this. TCP/IP ensures the reliable transmition of data. By using a socket you are automaticaly sure that the data is reliably transmitted (Unless there is some sort of exception).
    To get the size of the files you can use a File object. Look it up in java.io package in API documentation.
    java-code-snippet (without error checking)
    File clientFile = new File("input.txt");
    clientFile.length();

  • OSB Socket Protocol

    Hi Guru's,
    We are implementing Oracle Service Bus in our Organization. I am the new "SOA Guy" for this project. I have configured OSB 11.1.1.3 version on my machine. And i am done with all the tutorials provide for OSB. I even successfully tested a real time webservice using soap/http.
    Now, we want to test some WS's by using TCP connections. There is a sample tutorial for the same as well.
    **http://download.oracle.com/docs/cd/E13159_01/osb/docs10gr3/transportsdk/example.html**
    However, when i tried to configure the Business Service, I did not find any option for "Socket " Protocol in the dropdown list of protocols for connectivity.
    Do, I need to install socket server on OSB to get the "Socket" option avaiable int he list of protocols.
    Please, give me all the steps nessesary to do this.
    Thanks
    Salil

    Hi Salil,
    Follow the below url for socket transport under protocol list
    http://download.oracle.com/docs/cd/E13159_01/osb/docs10gr3/transportsdk/example.html.
    naviagte to ALSB_HOME/samples/servicebus/sample-transport location try to run ant build,ant stage and ant deploy .
    Before that set the environment variables and classpath for respective jars like weblogic.jar,sb-kernel-api.jar,com.bea.core.xml.xmlbeans_2.1.0.0_2-5-1.jar,alsb.jar,com.bea.common.configfwk_1.5.0.0.jar etc.
    and check the following links:
    OSB - Socket Transport Example
    com.bea.wli.sb.transports.TransportException

Maybe you are looking for

  • How to pass a large value to a parameter of a service

    Hi Everyone, I need to execute service GET_SEARCH_RESULTS and want to provide values to its parameter QueryText. I am calling the service in the following manner: http://localhost/idc/idcplg?IdcService=GET_SEARCH_RESULTS&QueryText=<$keyTagID$>&ftx=&A

  • Business object for AP invoice transaction FB60

    hi all,         Which business Object is triggered when we AP invoice is created transaction FB60 thanks in advance Naval Bhatt

  • Pdf download problem in lion

    Safari can download most files ok. But, pdf downloads result in a dark blank screen and no download.  There is no problem downloading in Chrome. Repairing permissions hasn't worked

  • How to display any 'String' bydefault  in a JComboBox

    Hi, Plz let me know how any string can be shown bydefault in a JComboBox and when the user selects this combobox then the list will appear in the combobox. Thanks, Rohit.

  • Numbers 08 calculationg wrong on mavericks

    hi community, i upgraded to mavericks but numbers is calculating completely wrong now. all my spreadsheets became unusable. as apple works is not working any more too, it seems to be a big problem for me. while browsing the web i realised that other