Note that there are some explanatory texts on larger screens.

plurals
  1. POsend data from .Net application to android app via network (socket programming)
    primarykey
    data
    text
    <p>I'm new in socket programming. I want to create an application for PC using C# and an application for android phones witch can communicate with other via wireless network(LAN).</p> <p>For sending data to android app, I'm using this code in PC side:</p> <pre><code> private void sendButton_Click(object sender, EventArgs e) { try { Object objData = messageTextBox.Text; byte[] byData = System.Text.Encoding.ASCII.GetBytes(objData.ToString ()); _socket.Send (byData); } catch(SocketException se) { MessageBox.Show (se.Message ); } } private void Form1_Load(object sender, EventArgs e) { try { _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); _ipEndPoint = new IPEndPoint(IPAddress.Parse("192.168.1.18"), 2001); _socket.Connect(_ipEndPoint); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } </code></pre> <p>In android app, I want to receive data with this code:</p> <pre><code>Handler myUpdateHandler = new Handler() { public void handleMessage(Message msg) { Log.d(appTag, "setting textview"); TextView tv = (TextView) findViewById(R.id.messageText); tv.setText(mClientMsg); } }; class CommsThread implements Runnable { public void run() { try { Socket s = null; try { ss = new ServerSocket(2001); } catch (IOException e) { Log.d(appTag, e.toString()); } while (!Thread.currentThread().isInterrupted()) { Message m = new Message(); Log.d(appTag, "message m = new message()"); try { if (s == null) s = ss.accept(); BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream())); String line = null; while ((line = in.readLine()) != null) { Log.d(appTag, line); mClientMsg = line; } myUpdateHandler.sendMessage(m); } catch (IOException e) { Log.d(appTag, e.toString()); } } } catch (Exception e) { Log.d(appTag, e.toString()); } } } </code></pre> <p>But android application will not receive any data.</p> <p>can anyone help me to solve my problem? I'm very noob in socket programming.</p> <p>sorry for bad english. thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload