C# client namespaces
----------------
1.System
2.System.Net.Sockets
3.System.IO;
java packages
--------------
1.java.net
2.java.io
Java server Application
import java.net.*;
import java.io.*;
public class java_server
{
public static void main(String h[])
{
try
{
ServerSocket ss=new ServerSocket(1800);
Socket s=ss.accept();
System.out.println("Client Accepted");
BufferedReader br=new BufferedReader(new
InputStreamReader(s.getInputStream()));
System.out.println(br.readLine());
PrintWriter wr=new PrintWriter(new
OutputStreamWriter(s.getOutputStream()),true);
wr.println("Welcome to Socket Programming");
}catch(Exception e){System.out.println(e);}
}
}
Compile using
javac java_server.java
C# client Application
using System;
using System.Net.Sockets;
using System.IO;
class csharp_client
{
public static void Main(string[] args)
{
try{
TcpClient tc=new TcpClient("server",1800);// in the place of server, enter
your java server's hostname or Ip
Console.WriteLine("Server invoked");
NetworkStream ns=tc.GetStream();
StreamWriter sw=new StreamWriter(ns);
sw.WriteLine("My name is Pramod.A");
sw.Flush();
StreamReader sr=new StreamReader(ns);
Console.WriteLine(sr.ReadLine());
}catch(Exception e){Console.WriteLine(e);}
}
}
Compile using the command
csc /r:System.dll csharp_client.cs
After compilation, run the java server first
java java_server
Then run the c# client application
csharp_client
Related posts:
- Sockets Programming in Java
- Howto PHP / Java bridge on Debian
- Ubuntu Howto: Install Sun Java
- Dalvik: How Google routed around Sun’s IP-based licensing restrictions on Java ME
- Java default keystore password – cacerts
- Debugging Server-side Code through IntelliJ IDEA or Eclipse with BEA Weblogic 8.1
- Howto install Sun Java on Debian Sarge
- Howto Install Sun Java on Debian Etch
- Generic SOAP/WSDL Client
- Java and C benchmark