This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
    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: 24212
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