Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 902293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:41:41+00:00 2026-05-15T15:41:41+00:00

I need to pass a native winsock socket created by C++ application to a

  • 0

I need to pass a native winsock socket created by C++ application to a library in my application that uses java.net.Socket to connect to a server.
This Winsock appication already take care of connecting the socket.

How can I explicitly set the socket descriptor of java.net.Socket?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T15:41:42+00:00Added an answer on May 15, 2026 at 3:41 pm

    I encountered such a problem on Unix, not sure if the same mechanism works for you with WinSock.

    In our case, a program in C creates a socket using special hardware. The C program spawns the Java program passes it the socket. The Java program then constructs input/output stream from the file descriptor of the socket so it can read/write to it just like a normal socket.

    The Java code snippet is here,

        Class<FileDescriptor> clazz = FileDescriptor.class;
    
        Constructor<FileDescriptor> c;
        try {
                c = clazz.getDeclaredConstructor(new Class[] { Integer.TYPE });
        } catch (SecurityException e) {
                e.printStackTrace();
                return;
        } catch (NoSuchMethodException e) {
                e.printStackTrace();
                return;
        }
    
        c.setAccessible(true);
        FileDescriptor fd;
        try {
                fd = c.newInstance(new Integer(socket));
        } catch (IllegalArgumentException e) {
                e.printStackTrace();
                return;
        } catch (InstantiationException e) {
                e.printStackTrace();
                return;
        } catch (IllegalAccessException e) {
                e.printStackTrace();
                return;
        } catch (InvocationTargetException e) {
                e.printStackTrace();
                return;
        }
    
        FileOutputStream os = new FileOutputStream(fd);
        FileInputStream is = new FileInputStream(fd);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to pass a hwnd to a native dll that is going to
I need to pass configuration settings to an AddIn created using the Managed AddIn
In my application(GWT(EXT_GWT) + Spring) I need to set user(after login) his native language,
We have an application that currently supports Oracle and SQL Server databases. We're in
My Java application require a huge memory heap. I need to launch my application
I have a netty web socket server running to which various native javascript clients
I am developing an application that needs to a host native Win32 window and
What is the best way to implement GWT Server Side Internationalization? Use native Java
Let us consider that we need to pass a structured form of callbacks to
I want to use Database mail for my application and this means I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.