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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:58:17+00:00 2026-05-19T05:58:17+00:00

I have a very simple server written in C and an equally simple client

  • 0

I have a very simple server written in C and an equally simple client written in Java. When I run them both on the same computer everything works, but when I try to run the server on computer A and the client on computer B, I get the error IOException connection refused from the java client. I can’t seem to find out whats happening, any thoughts? I’ve even turned off the firewalls but the problem still persists.

server.

#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>

#define PORT 3557
#define BUF 256

int main(int argc, char *argv[])
{
    struct sockaddr_in host, remote;
    int host_fd, remote_fd;
    int size = sizeof(struct sockaddr);;

    char data[BUF];

    host.sin_family = AF_INET;
    host.sin_addr.s_addr = htonl(INADDR_ANY);
    host.sin_port = htons(PORT);
    memset(&host.sin_zero, 0, sizeof(host.sin_zero));

    host_fd = socket(AF_INET, SOCK_STREAM, 0);
    if(host_fd == -1) {
        printf("socket error %d\n", host_fd);
        return 1;
    }

    if(bind(host_fd, (struct sockaddr *)&host, size)) {
        printf("bind error\n");
        return 1;
    }

    if(listen(host_fd, 5)) {
        printf("listen error");
        return 1;
    }

    printf("Server setup, waiting for connection...\n");
    remote_fd = accept(host_fd, (struct sockaddr *)&remote, &size);

    printf("connection made\n");

    int read = recv(remote_fd, data, BUF, 0);
    data[read] = '\0';
    printf("read = %d, data = %s\n", read, data);

    shutdown(remote_fd, SHUT_RDWR);
    close(remote_fd);

    return 0;
}

client.

import java.net.*;
import java.io.*;

public class socket {

    public static void main(String[] argv) {
        DataOutputStream os = null;

        try {
            Socket socket = new Socket("192.168.1.103", 3557);
            os = new DataOutputStream(socket.getOutputStream());
            os.writeBytes("phone 12");

            os.close();
            socket.close();

        } catch (UnknownHostException e) {
            System.out.println("Unkonw exception " + e.getMessage());

        } catch (IOException e) {
            System.out.println("IOException caught " + e.getMessage());
        } 
    }
}

Edit:

Thanks everyone for the quick responses (I was shocked). I solved the problem thanks to the suggestions of using telnet and nc. I found out that my firewall was blocking port 3557 on the server machine. A simple thing I should have thought of, 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-05-19T05:58:18+00:00Added an answer on May 19, 2026 at 5:58 am

    There are many possible problems and you should start and try pinpointing the problematic part.

    It just might be a networking problem – B might not be able to connect to A because of firewalls and the likes.

    To check this you can start with running a port scan from B on A (nmap -p 3557 192.168.1.103 to check if the port seems open to computer B).

    If it looks open, you can try connecting with telnet/nc from B instead of your client to see if the server works as expected: telnet 192.168.1.103 3557 or nc 192.168.1.103 3557 and once connected write “phone 12” and see what you get.

    These should help you understand which part is causing problems, server, client or network.

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

Sidebar

Related Questions

I have written a very simple socket server. It listens in post 63254. First
I have written a VERY simple MVC application which just displays a single string
I have a very simple code snitppet that looks like this: <asp:Label Text=$Name$ runat=server
I have recently written a socket server in PHP that will be handling communication
Very soon I will setting up a web server for a client who has
I have a very simple SQL table that I want to import into Solr
I have a very simple task called update_feeds: desc Update feeds task :update_feeds do
I have a LAMP server with 256MB RAM (poor man's server in cloud). I
I am developing an iPhone app and would like to create some sort of
I'm using C# .net library System.Speech to implement my ASR app ( BTW, I've

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.