This is the code I use to do what you're trying to do, I'm not sure
about the usage of DataOutputStream as that's the main difference I
see in terms of setting up my socket and your setup.
private boolean connect(String ip, String port)
{
try
{
InetAddress serverAddr = InetAddress.getByName(ip);
int iport = Integer.parseInt(port);
if (iport < 0)
{
throw (new NumberFormatException());
}
if (defaultip.equals(""))
{
throw (new UnknownHostException());
}
connection = new Socket(serverAddr, iport);
// initialize the output stream to send data to server
out = connection.getOutputStream();
;
return true;
}
catch (Exception e)
{
return false;
}
On Mar 23, 3:23 am, Honest <[email protected]> wrote:
> Hello,
>
> I am able to connect to TCP IP netwrok but even if i am sending some
> byte array but yet i am not seeing any output on Server console.
> Server is C++ and i need to send data from my android apps. I am able
> to connect but when i send data i am not getting any notification. the
> followins is my code.
>
> InetAddress serverAddr = InetAddress.getByName(serverIP);
> SocketAddress socketadd= new InetSocketAddress(serverAddr,
> serverPort);
> Log.d("TCP", "C: Connecting...");
>
> //Socket socket = new Socket(serverAddr, serverPort);
> Socket socket=new Socket();
>
> try {
> Log.d("TCP", "C: Sending: '" + msg + "'");
> socket.connect(socketadd);
> Log.e("Connect:", "Connect:");
> DataOutputStream dataout = new
> DataOutputStream(socket.getOutputStream());
> dataout.flush();
>
> byte haeader[]=new byte[6];
> // String data="20110110,cswxerotest,cswxerotest";
> // Packet p=new Packet();
> //byte bdata[]=converttoCPP(getBytes());
>
> byte bdata[]=getBytes();
> //byte a[]=new byte[20];
>
> //dataout.writeByte(5);
> dataout.write(bdata,0,bdata.length);
> dataout.flush();
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en