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 7805685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:17:48+00:00 2026-06-02T02:17:48+00:00

Server (java): public static void main(String[] args) { //single threaded for now try {

  • 0

Server (java):

public static void main(String[] args) {


//single threaded for now

try {

    //very magic #
    ServerSocket service = new ServerSocket(33000); 

    while(true) {

    debug("Begin waiting for connection");

    //this spins
    Socket connection = service.accept();

    debug("Connection received from " + connection.getInetAddress().getHostName());

    ObjectOutputStream out = new ObjectOutputStream(connection.getOutputStream());
    ObjectInputStream in = new ObjectInputStream(connection.getInputStream());

// ...

client (C) – this is exactly the sample code from http://www.linuxhowtos.org/data/6/client.c

int main(int argc, char *argv[])
{
int sockfd, portno, n;
struct sockaddr_in serv_addr;
struct hostent *server;

char buffer[256];
if (argc < 3) {
   fprintf(stderr,"usage %s hostname port\n", argv[0]);
   exit(0);
}
portno = atoi(argv[2]);
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0)
    error("ERROR opening socket");
server = gethostbyname(argv[1]);
if (server == NULL) {
    fprintf(stderr,"ERROR, no such host\n");
    exit(0);
}
bzero((char *) &serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
bcopy((char *)server->h_addr,
     (char *)&serv_addr.sin_addr.s_addr,
     server->h_length);
serv_addr.sin_port = htons(portno);
if (connect(sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0)
    error("ERROR connecting");
printf("Please enter the message: ");
bzero(buffer,256);
fgets(buffer,255,stdin);
n = write(sockfd,buffer,strlen(buffer));
if (n < 0)
     error("ERROR writing to socket");
bzero(buffer,256);
n = read(sockfd,buffer,255);
if (n < 0)
     error("ERROR reading from socket");
printf("%s\n",buffer);
close(sockfd);
return 0;
}

Java is not happy:

Begin waiting for connection
Connection received from localhost
Fatal Exception: invalid stream header: 68657920
java.io.StreamCorruptedException: invalid stream header: 68657920
        at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:801)
        at java.io.ObjectInputStream.<init>(ObjectInputStream.java:298)
        at Scanner.main(Scanner.java:243)

line 243 is:

ObjectInputStream in = new ObjectInputStream(connection.getInputStream());

The C client works with the C server, and the C server works with my Python client. Similar Java servers I’ve written have worked with Java clients. So as far as I can tell there’s some magic words to get Java server -> non-Java client. Sorry, I’ve had no luck on the Google with this, despite it being obviously very basic and simple. Thanks.

  • 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-02T02:17:50+00:00Added an answer on June 2, 2026 at 2:17 am

    You’re using an ObjectInputStream on the Java side, which expects a very specific protocol of serialized Java objects. Unless you write the correct format to the socket from the C client, this is exactly the error you will get. You haven’t shown how you try to read from the stream, but I suspect you just want a BufferedInputStream instead.

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

Sidebar

Related Questions

import java.io.*; import java.net.*; public class Server{ public static void main(String[] args) throws SocketException,
After reading: Getting the 'external' IP address in Java code: public static void main(String[]
Here is the server code package echoserver; import java.net.*; import java.io.*; public class EchoServer
I've got a java server (not web based, more like a big, many-threaded standalone
I have following code for a chat server application in Java - public synchronized
I have a very simple Java RMI Server that looks like the following: import
When you google for multi-threaded java server , most of the time you'll get
I am trying to connect to a standalone desktop tcp server(java) from tcp client
I have a java server which is using TCP and sockets to connect to
We've got a Java server application that runs on a number of computers, all

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.