i want to send data from one computer to another using socket.how can i start it any idea.please help me.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
i want to send data from one computer to another using socket.how can i start it any idea.please help me.
Did you try google? One of the top hits: All About Sockets
Moved to - Java Networking - Java Programming Forums
Do a search on the forums for Socket or client server. This has been answered before.
Please use [highlight=Java] code [/highlight] tags when posting your code.
Forum Tip: Add to peoples reputation by clicking the button on their useful posts.
/*yes i have solved the socket programe.but now my problem is to send string to server from client
my client programe is*/
import java.net.*;
import java.io.*;
import java.util.*;
public class Client12
{
public static void main(String args[])
{
try
{
Client12 world=new Client12();
}catch(IOException e){}
}
static final public int PortNumber =8000;
public Client12()throws IOException
{
Scanner as=new Scanner(System.in);
Socket S=new Socket("127.0.0.1",PortNumber);
DataInputStream fromserver=new DataInputStream(S.getInputStream());
//BufferedReader BR=new BufferedReader(R);
DataOutputStream toserver=new DataOutputStream(S.getOutputStream());
//int rad=0;
/*for(
{
System.out.print("enter=");
int rad=as.nextInt();
System.out.print("you have entered=="+rad);
toserver.writeInt(rad);
int r=fromserver.readInt();
fromserver.flash();
System.out.println("\nreply From Server:\n"+r);
}*/
//here is my String
String s="sdf".trim();
OutputStreamWriter out
= new OutputStreamWriter(S.getOutputStream( ));
\\here im sending the STRING
out.write(s);
}
}
//it doesnt show any error.but when i run the server it doesnt print the STRING which i send from client
//my server programe is bellow
//---------------------------------------------------------------------------------------------------------------------------
import java.net.*;
import java.io.*;
import java.util.*;
import java.lang.Object;
public class Server12
{
public static void main(String args[])
{
try
{
Server12 world=new Server12();
}catch(IOException e){}
}
static final public int PortNumber =8000;
public Server12()throws IOException
{
ServerSocket SS=new ServerSocket(PortNumber);
Socket S=SS.accept();
while(true)
{
System.out.println("\nWaiting....Run the Client Program");
// Socket S=SS.accept();
System.out.println("\nClient found and Message Shown");
//OutputStreamWriter OSW=new OutputStreamWriter(S.getOutputStream());
ObjectInputStream fromclient;
fromclient =new ObjectInputStream(S.getInputStream());
DataOutputStream toclient=new DataOutputStream(S.getOutputStream());
Object sd=fromclient.readLine();
System.out.print("sdf"+sd);
String Msg="Current Date And Time on Server is:"+new Date()+"\n";
//OSW.write(Msg);
// OSW.close();
}
}
}
/*please help me.
i cant understand why the programe doesnt response for String transmition.*/
Last edited by talha07; January 22nd, 2011 at 01:59 PM.