Bookmark Topic Watch Topic
  • New Topic

sending my name

 
Lucky Singh
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Report post to moderator
import java.io.*;
import java.net.*;
public class KnockKnockClient
{
public static void main(String[] args) throws IOException
{
Socket kkSocket = null;
PrintWriter out = null;
try
{
kkSocket = new Socket("taranis", 4444);
out = new PrintWriter(kkSocket.getOutputStream(), true);
}
catch (UnknownHostException e)
{
System.err.println("Don't know about host: taranis.");
System.exit(1);
}
catch (IOException e)
{
System.err.println("Couldn't get I/O for the connection to:
taranis.");
System.exit(1);
}
String fromUser = new String("Lucky Singh");;
while ((fromUser = in.readLine()) != null)
{
if (fromUser != null)
{
out.println(fromUser);
}
}
out.close();
kkSocket.close();
}
}
Is the aboev code correct for sending my name to a server?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please don't cross-post. Finish the conversation you started here.
 
    Bookmark Topic Watch Topic
  • New Topic