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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T14:14:03+00:00 2026-06-16T14:14:03+00:00

I am trying to write a simple client server program. Both client and server

  • 0

I am trying to write a simple client server program. Both client and server is programmed in java and connected via Access Point as Local Area Network, the server is my laptop(computer) and the client is my android device. Here is code for the client side (android):

package com.caisar.andronet;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class Main extends Activity {

    private Button mSendButton;
    private EditText ipInput;
    private EditText portInput;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mSendButton = (Button) findViewById(R.id.button1);
        ipInput = (EditText) findViewById(R.id.editText1);
        portInput = (EditText) findViewById(R.id.editText2);

        mSendButton.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                try {
                    sendPacket();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }

        });
    }

    public void sendPacket() throws IOException
    {
        int port = Integer.parseInt(portInput.getText().toString());
        InetAddress address = InetAddress.getByName(ipInput.getText().toString());
        String message = "Ini adalah caisar oentoro";
        byte[] messages = message.getBytes();
        DatagramSocket socket = new DatagramSocket();
        DatagramPacket packet = new DatagramPacket(messages, messages.length, address, port);
        socket.send(packet);
        socket.close();
    }

}

And this is the server program:

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

class DatagramReceiver{
public static void main(String[] args){
    try
    {
        int MAX_LEN = 40;
        int localPort = Integer.parseInt(args[0]);
        DatagramSocket socket = new DatagramSocket(localPort);
        byte[] buffer = new byte[MAX_LEN];
        DatagramPacket packet = new DatagramPacket(buffer, MAX_LEN);
        socket.receive(packet);
        String message = new String(buffer);
        System.out.println(message);
        socket.close();
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
   }
 }

The problem is, when trying the server program on Ubuntu, it works well without any trouble, but when I tried that on Windows, the server program didn’t show any response. So what is the trouble that ‘blocks’ the server from listening or accepting data sent from client?

  • 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-16T14:14:05+00:00Added an answer on June 16, 2026 at 2:14 pm

    Hey thank you, that works well. But is there any other way better than turning off windows firewall? I’m using windows 7.

    Instead of turning off the whole firewall, you can open the specific port(s) used for UDP (or TCP is that is what you are using) This turns off the firewall just for the port you need.

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

Sidebar

Related Questions

i'm trying to write simple tcp\ip client-server. here is server code: internal class Program
I'm trying to write a simple client/server chat application in 2 languages - Java
I'm trying to write a simple server-client program, but I have a problem: I
I am trying to write a very simple unix domain datagram client/server. Here is
i'm trying to write simple C openssl client and server. Here is client's code:
I am trying to create a simple voucher program. Client connects to server and
I'm trying to write simple client and server C programs, communicating with each other
Was trying to write simple client and server recieveing/sending data through TMemoryStream . When
I'm trying to write a simple WCF Server + gSOAP client proof-of-concept application using
i have a weird problem. I am trying to write simple Client - Server

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.