//java socket client example
import java.io.*;
import java.net.*;
public class socket_client
{
public static void main(String[] args) throws IOException
{
Socket s = new Socket();
String host = "dev.easy-conn.com";
PrintWriter s_out = null;
BufferedReader s_in = null;
try
{
s.connect(new InetSocketAddress(host , 6557));
System.out.println("Connected");
//writer for socket
s_out = new PrintWriter( s.getOutputStream(), true);
//reader for socket
s_in = new BufferedReader(new InputStreamReader(s.getInputStream()));
}
//Host not found
catch (UnknownHostException e)
{
System.err.println("Don't know about host : " + host);
System.exit(1);
}
//Send message to server
String message = "GET hosts\r\n\r\n";
s_out.println( message );
System.out.println("Message send");
//Get response from server
String response;
while ((response = s_in.readLine()) != null)
{
System.out.println( response );
}
}
}
Showing posts with label java. Show all posts
Showing posts with label java. Show all posts
Monday, July 8, 2013
Sending and Receiving Data use Java socket programming
Friday, April 13, 2012
Thursday, April 21, 2011
IntelliJ IDEA在Linux下很卡的问题解决
idea.vmoptions 文件加入
[cc lang="text"]-Dsun.java2d.pmoffscreen=false[/cc]
[cc lang="text"]-Dsun.java2d.pmoffscreen=false[/cc]
Subscribe to:
Posts (Atom)