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

  • Home
  • SEARCH
  • 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 8613657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:56:09+00:00 2026-06-12T04:56:09+00:00

I am trying to make a tcp request in Java to a existing TCP

  • 0

I am trying to make a tcp request in Java to a existing TCP server that is already available.
the interface specification is:

Field           Length      Type
Length          2 bytes     16-bits binary
Message ID      1 byte      8-bits binary
MSGTYPE         1 byte      8-bits binary
Variable1       4 bytes     32-bits binary
Variable2       30 bytes    ASCII
Variable3       1 byte      8-bits binary

I understand how to convert a String to Binary using BigInteger.

String testing = "Test Binary";
byte[] bytes = testing.getBytes();
BigInteger bi = new BigInteger(bytes);
System.out.println(bi.toString(2));

My Understanding is that if i wanted to make a TCP request i would first

  1. need to convert each binary to a string
  2. append the values to a StringBuffer.

Unfortunately my understanding is limited so i wanted some advice on creating the TCP request correctly.

  • 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-06-12T04:56:10+00:00Added an answer on June 12, 2026 at 4:56 am

    I wouldn’t use String (as you have binary data), StringBuffer (ever), or BigInteger (as it not what its designed for).

    Assuming you have a Big Endian data stream I would use DataOutputStream

    DataOutptuStream out = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream()));
    
    out.writeShort(length);
    out.write(messageId);
    out.write(msgtype);
    out.write((var1+"\0\0\0\0").substring(0, 4).getBytes("ISO-8859-1"));
    out.write(var2.getBytes("ISO-8859-1"));
    out.write(var2);
    
    out.flush(); // optionally.
    

    If you have a little endian protocol, you need to use ByteBuffer in which case I would use a blocking NIO SocketChannel.

    BTW I would use ISO-8859-1 (8-bit bytes) rather than US-ASCII (7-bit bytes)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a Java TCP client and a node.js TCP server talk
i'm trying to make a php tcp/ip server with the following code: <?php //
I'm trying to make a simple TCP server using Twisted ,which can do some
I'm trying to make a simple chat server in Java. Now I have a
I've been trying to make a non-blocking TCP server of sorts using tcp::acceptor. I've
I'm trying to make a server that can be connected to by multiple clients.
I'm trying to build a file server using Java TCP sockets. I keep getting
I am trying to make a simple game that goes across a TCP network.
I'm trying to make a simple C# web server that, at this stage, you
I'm trying make an entity with doctrine that has three associations with other entities

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.