public static final int SERVERPORT = 4444;
public void server()
{
DataOutputStream os=null;
DataInputStream is = null;
ServerSocket socket = null;
Socket ClientSocket = null;
String out = null;
try
{
socket = new ServerSocket(SERVERPORT);//10.0.2.2
if(socket == null)
{
Log.d("TagServer()", "socket null");
}
else
{
Log.d("TagServer()", "Waiting...");
ClientSocket = socket.accept();
os = new DataOutputStream(ClientSocket.getOutputStream());
is = new DataInputStream(ClientSocket.getInputStream());
/* By magic we know, how much data will be waiting for us*/
byte[] buf = new byte[100];
int readLen = 0;
while((readLen = is.read(buf, 0, 100)) != -1)
{
out = new String(buf, 0, readLen-1);
Log.d("TCP", out);
os.writeBytes("end");
}
os.close();
is.close();
socket.close();
ClientSocket.close();
Log.d("TagServer()", "Finished");
}
}
catch(Exception e)
{
System.out.println(e);
Log.d("TagServer()", e.toString());
}
}
i think you can understand it.
2008/11/17 川邊泰誌 <[EMAIL PROTECTED]>
> Hi,
>
> I had tried to give the permission "android.permission.INTERNET",
> using telnet and execute a command "redir add tcp:400:400".
> But, same exception "A java.net.BindException" was thrown.
>
> It questions again.
> Is it possible to use the ServerSocket class in Android ?
>
> The following are my codes.
> //! STR my code
> try
> {
> ServerSocket srvrSock = new ServerSocket(400);
> }
> catch(IOException e)
> {
> e.printStackTrace();
> }
> catch(Exception e)
> {
> e.printStackTrace();
> }
> //! END my code
>
>
> Thank you for any pointers.
>
> riverwide
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---