0% found this document useful (0 votes)
8 views5 pages

TCP Server Client Program

The document contains Java code for a DayTime server and client that communicates the current date and time. It also includes a TCP server and client program that allows for continuous chatting between the server and client. Both server and client programs utilize sockets for network communication and handle input/output streams for data exchange.

Uploaded by

sagarhowal38
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views5 pages

TCP Server Client Program

The document contains Java code for a DayTime server and client that communicates the current date and time. It also includes a TCP server and client program that allows for continuous chatting between the server and client. Both server and client programs utilize sockets for network communication and handle input/output streams for data exchange.

Uploaded by

sagarhowal38
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

//Server Program

import [Link].*;
import [Link].*;
import [Link].*;
class DayTimeServer
{
public static void main(String args[]) throws IOException
{
ServerSocket oServer=new ServerSocket(40);
[Link]("Server is Wiating for Client...");
Socket oClient=[Link]();
[Link]("Client is Connected..");

Date now=new Date();


DataOutputStream dOut=new DataOutputStream([Link]());
[Link]("Date:"+[Link]());
[Link]();

}
}
//Client Program
import [Link].*;
import [Link].*;
class DayTimeClient
{
public static void main(String args[]) throws IOException,UnknownHostException
{
String strHost="localhost";
[Link]("Client is waiting for Server...");
Socket oClient=new Socket(strHost,40);
[Link]("Server Connected");
DataInputStream dIn=new DataInputStream([Link]());
[Link]([Link]());
[Link]();
}
}
//Client Server Chatting Program
//Server Program
import [Link].*;
import [Link].*;
import [Link].*;
class TCPServer
{
public static void main(String args[]) throws IOException
{
ServerSocket oServer=new ServerSocket(13);
[Link]("Server is Wiating for Client...");
Socket oClient=[Link]();
[Link]("Client is Connected..");
while(true)
{
DataInputStream dIn=new DataInputStream([Link]());
[Link]([Link]());

Scanner sc=new Scanner([Link]);


String strVal=[Link]();
DataOutputStream dOut=new DataOutputStream([Link]());
[Link]("Server:"+strVal);
}
}
}
//Client Program
import [Link].*;
import [Link].*;
import [Link].*;
class TCPClient
{
public static void main(String args[]) throws IOException,UnknownHostException
{
String strHost="localhost";//"[Link]";
[Link]("Client is waiting for Server...");
Socket oClient=new Socket(strHost,13);
[Link]("Server Connected");
while(true)
{
Scanner sc=new Scanner([Link]);
String strVal=[Link]();
DataOutputStream dOut=new DataOutputStream([Link]());
[Link]("Client:"+strVal);

DataInputStream dIn=new DataInputStream([Link]());


[Link]([Link]());
}
}
}

You might also like