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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:41:22+00:00 2026-06-07T07:41:22+00:00

I want to send a string from Android to my PC (visual basic 2010)

  • 0

I want to send a string from Android to my PC (visual basic 2010) i try this one but it’s not working. Please anyone help me..

I get my Android Code from :
http://thinkandroid.wordpress.com/2010/03/27/incorporating-socket-programming-into-your-applications/

And its Look Like :

package com.zelacroix.bukumenu;
import java.io.*;
import java.net.*;
import android.app.Activity;
import android.os.*;
import android.util.*;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;
public class TesKirim extends Activity {

        private EditText serverIp;

        private Button connectPhones;

        private String serverIpAddress = "192.168.1.2";

        private boolean connected = false;

        private Handler handler = new Handler();

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.teskirim);

            serverIp = (EditText) findViewById(R.id.server_ip);
            connectPhones = (Button) findViewById(R.id.connect_phones);

            connectPhones.setOnClickListener(new OnClickListener() {
            @Override
                public void onClick(View v) {
                    if (!connected) {
                        serverIpAddress = serverIp.getText().toString();
                        if (!serverIpAddress.equals("")) {
                            Thread cThread = new Thread(new ClientThread());
                            Toast.makeText(getApplicationContext(), 
                                               "masuk if",  
                                               10)
                                .show();
                            cThread.start();
                        }
                    }
                }
            });
        };

        public class ClientThread implements Runnable {
            public void run() {
                try {
                    InetAddress serverAddr = 
                        InetAddress.getByName(serverIpAddress);
                    Log.d("ClientActivity", "C: Connecting...");
                    Socket socket = new Socket(serverAddr , 10000);
                    connected = true;
                    while (connected) {
                        try {
                            Log.d("ClientActivity", "C: Sending command.");
                            PrintWriter out = 
                                new PrintWriter(
                                    new BufferedWriter(
                                        new OutputStreamWriter(
                                            socket.getOutputStream())), 
                                    true);

                                // where you issue the commands
                                out.println("Hey Server!");
                                Log.d("ClientActivity", "C: Sent.");
                        } catch (Exception e) {
                            Log.e("ClientActivity", "S: Error", e);
                        }
                    }
                    socket.close();
                    Log.d("ClientActivity", "C: Closed.");
                } catch (Exception e) {
                    Log.e("ClientActivity", "C: Error", e);
                    connected = false;
                }
            }
        };
};

my Visual Basic is using UDP method.. And its Look Like :

Imports System.Net.Sockets
Imports System.Net
Imports System.IO
Imports System.Text

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, 
                              ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim udp_Client As New UdpClient(10000)

            Dim remoteIpEndPoint As New IPEndPoint(IPAddress.Any, 0)

            Dim receiveBytes As [Byte]() = udp_Client.Receive(remoteIpEndPoint)
            Dim returnData As String = Encoding.ASCII.GetString(receiveBytes)
            ListBox1.Items.Add(returnData.ToString)
            udp_Client.Close()
        Catch ex As Exception
            ListBox1.Items.Add(ex.ToString())
        End Try
    End Sub
End Class

Please I really2 need to comunicate them..

  • 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-07T07:41:25+00:00Added an answer on June 7, 2026 at 7:41 am

    I think the problem is caused since you are mixing TCP and UDP communication. The Visual basic app is expecting to receive data over UDP and the Android App is sending over TCP. I created the Android and VB projects from your code and called following UDP send function from the android app and the communication works fine. The string from Android appears correctly in the listbox in the VB app. Try using UDP sockets from your android app as follows:

    private void udp_send(String serverIpAddress) throws IOException
            {
                String messageStr="Hello Android!";
                int server_port = 10000;
                DatagramSocket s = new DatagramSocket();
                InetAddress local = InetAddress.getByName(serverIpAddress);
                int msg_length=messageStr.length();
                byte[] message = messageStr.getBytes();
                DatagramPacket p = new DatagramPacket(message, msg_length,local,server_port);
                s.send(p);
            }
    

    [i tried this code on an android simulator and the VB app running on the same machine. in case you are trying accross different machines and still face problems with the above code, make sure that the udp traffic for the port 10000 is not stopped by some firewall. You can give the detailed exception log from the Android app for us to better understand the problem if necessary]

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

Sidebar

Related Questions

i want to send data from android application to server (.NET) but it doesn't
i want to send data from android application to local server (PHP) but it
I want to send mail from my android application to given address. But now
I want to send String from C# to Jave I do it in C#
I want to create one application which send email with attachment(select file from SD
I'm working on an android app that has to send and receive information from
I'm struggeling with code from this page: http://www.androidsnippets.com/encrypt-decrypt-between-android-and-php I want to send data from
I want to send email from my application without configuration email in android device.
i want to send a json string from a html webpage using javascript to
I am facing a problem to call https from Android. Can any one please

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.