help .NET socket for andoid

hi all,
Does anyone have document about connect from client to server ?
is it the same on window?

It should be the same as the mono library Unity uses is ‘copying’ microsofts library. Try it and see.

thanks @KHopcraft

I created a client program on android, windows server.
It works fine on windows. but on android, the TCP client cannot connect to the server.
help me ! :frowning:

private TcpClient myClient = new TcpClient();
public TcpClient MyClient
        {
            get { return myClient; }
        }
public void SendConnection()
    {   
        try
        {   
            if (!isConnected)
            {        
                myClient.Connect(new IPEndPoint(IPAddress.Parse(ipAdress), sPort));
                isConnected = true;        
                if (myClient.Client.Connected)
                {
                    recieve = new Thread(new ThreadStart(ReceiveData));
                    recieve.Start();
                }
            }
        }
        catch(Exception ex)
        {
            Debug.Log("Can not connect to  Server   ,Exception ::"+ex.Message);
            throw new Exception(ex.Message);
        }
    }

I was under the impression that in order to use networking on Android you need the Android Pro version. I may be mistaken, however.

Quite right CJR, For Android And IOS to use .net sockets, you need pro version of Android and IOS respectively.

I’ve got a trial Pro (all devices Pro) but I’m still getting no connections, on windows it works fine, android doesn’t :frowning: what would I be doing wrong?
I have also policy server and so on…

Thanks in advance!

Maybe your IP / Server Address is wrong. Even if Android gets simulated on your PC, it’s a separate device with it’s own IP address. This means: 127.0.0.1 and localhost both target the Android device in emulator.

Hello Tobiass, I’m using domain, the server is up and running, also the cross-domain policy server. It’s sad, it’s the only thing missing for us… thanks for the tip.

(Solved) I decided to take out the policy verification on the code, and guess what, just worked, I feel a bit confused because sometimes and just does not work without it, and at this time it only works without it :frowning: anyway, its working now… thanks for the help…

Help me with this guys, I using an android to android TCP connection, the Server is ok, it has been tested with a native android App, but my Unity Android App is not connecting!
Here is my code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Runtime.Serialization.Formatters.Binary;
using System;
using System.IO;
using Newtonsoft.Json;
using System.Net;
using System.Net.Sockets;
using UnityEngine.Networking;



public class SockMan : MonoBehaviour {

    public Text myText;

    private bool socketReady;
    private TcpClient socket;
    private NetworkStream stream;
    private StreamWriter writer;
    private StreamReader reader;

    void Start() {
        print("Start");
        ConnectToServer();
    }

    public void ConnectToServer() {
        print("Setup");
        myText.text = "Setup...";
        if(socketReady)
            return;
        String host = "192.168.0.15";
        Int32 port = 8080;n

        try {
            print("Enter Try");
            myText.text = "Enter Try...";
            socket = new TcpClient(host, port);
            stream = socket.GetStream();
            writer = new StreamWriter(stream);
            reader = new StreamReader(stream);
            socketReady = true;
            myText.text = "Connected!";
            Send("{ \"type\": \"video\", \"value\": \"2.mp4\"}");
        } catch {}
    }

    private void Update() {
        if(socketReady) {
            if(stream.DataAvailable) {
                string data = reader.ReadLine();
                if(data != null)
                    OnIncomingData(data);
            }
        }
    }

    private void OnIncomingData(string data) {
        print("Server: " + data);
    }

    private void Send(string data) {
        myText.text = "Will send";
        if (!socketReady) {
            writer.WriteLine(data);
            writer.Flush();
            myText.text = "Sent";
        }
    }
}