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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:53:18+00:00 2026-05-23T23:53:18+00:00

I try to create a client server socket beetwen my droid(client) and my PC(server),

  • 0

I try to create a client server socket beetwen my droid(client) and my PC(server), when i am in local(over wifi) it work perfectely, but when il try over 3G i get this exception when the server try to get clientsocket.getOutputStream()

at java.lang.Thread.run(Unknown Source)
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at java.io.DataInputStream.readUnsignedShort(Unknown Source)
at java.io.DataInputStream.readUTF(Unknown Source)
at java.io.DataInputStream.readUTF(Unknown Source)

What’s the probleme, do eny one know the solution of this?
help please 🙁

The Server

public class Server {

ServerSocket serverSocket;
public LinkedBlockingQueue<CDRecCourseDisplay> recCours;
public LinkedList<ClientMail> clientMails;
static Server server;

public static Server getInstance(){
    if(server == null){
        server = new Server();
    }
    return server;
}

Server() {
    // TODO Auto-generated constructor stub
    try {
        serverSocket = new ServerSocket(54444);
        recCours = new LinkedBlockingQueue<CDRecCourseDisplay>(10);
        clientMails = new LinkedList<ClientMail>();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    this.start();
}

private void start(){
    new Thread(new Runnable() {
        @Override
        public void run() {
            // TODO Auto-generated method stub
            while (true){
                try {
                    Socket socket = serverSocket.accept();
                    new Thread(new Client(socket)).start();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            }
        }
    }).start();
}

class Client implements Runnable{

    Socket socket;
    DataInputStream in;
    DataOutputStream  out;

    public Client(Socket socket) {
        // TODO Auto-generated constructor stub
        this.socket = socket;
        if(socket == null) return;
        try {
            InputStream i = socket.getInputStream();
            OutputStream o = socket.getOutputStream();
            in = new DataInputStream(i);
            out = new DataOutputStream(o);

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

    @Override
    public void run() {
        // TODO Auto-generated method stub
        new Thread(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                while(true){
                    try {
                        out.writeUTF("Test Message");
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } 
                }
            }
        }).start();

        new Thread(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                while(true){
                    try {
                        String buf = in.readUTF();  
                        Log.d("MESSAGE", buf);
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } 
                }
            }
        }).start();
    }

}

}

and the client

class Client implements Runnable{

    Socket socket;
    DataInputStream in;
    DataOutputStream  out;

    public void run() {
        // TODO Auto-generated method stub
        boolean conected = false;
        while(!conected){
            try {
                Thread.sleep(500);
                socket = new Socket("213.233.216.25", 54444);
                in = new DataInputStream(socket.getInputStream());
                out = new DataOutputStream(socket.getOutputStream());
                conected = true;
            } catch (UnknownHostException e) {
                // TODO Auto-generated catch block
                Log.e("ERROR :", e.getMessage());
            } catch (IOException e) {
                // TODO Auto-generated catch block
                Log.e("ERROR :", e.getMessage());
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                Log.e("ERROR :", e.getMessage());
            }
        }

        new Thread(new Runnable() {

            public void run() {
                // TODO Auto-generated method stub
                while(true){
                    try {
                        String buf = in.readUTF();
                        log.d("MESSAGE", buf);
                        }
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }
        }).start();


        new Thread(new Runnable() {

            public void run() {
                // TODO Auto-generated method stub
                while(true){
                    try {
                        out.writeUTF("Test message from the phone");
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }
        }).start();
    }
}
  • 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-23T23:53:19+00:00Added an answer on May 23, 2026 at 11:53 pm

    Most networks (Wifi and 3G) use NAT. NAT allows outbound connections, but prevents inbound (internet to device) connections.

    When your server and device are both on the same network, as in your case, then this works as you are not traversing NAT gateway.

    Rationale: what you are trying to do (connecting from internet to device) will not work in most networks.

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

Sidebar

Related Questions

I create little SimpleXMLRPCServer for check ip of client. I try this: Server import
Basically I want to create a rock solid server. while (keepRunning.get()) { try {
Hy, i'm try to create a simple Telnet Server in python, but the server
I want to create a simple server client application, but i think there is
When I try to create a SQL Server Login by saying CREATE LOGIN [ourdomain\SQLAccessGroup]
snippet from The Server code : public void run() { try { // Create
I am trying to make a simple Client-Server application but when I execute the
I'm trying to implement a server-client socket program in Java that can support multiple
I am creating a socket server in C# and a client in PHP. The
so - I have this Socket (not XMLSocket, just Socket) client. I also have

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.