Java and C# Client Server Socket Programming
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
Popular Related Items »
Incoming search terms
- c# client server
- c# java socket
- java c# socket
- c# socket
- client server c#
- client server socket java
- c# client java server
- java serversocket
- socket programming java
- java server c# client
- client server socket programming
- socket c# java
- c# java communication
- c# socket server
- client server socket programming in java
- serversocket java
- java server socket
- socket c#
- c# server java client
- client server program in java
- java socket C#
- C# Client Server Socket Programming
- socket java c#
- c# client server socket
- client server socket
- socket programming in java
- C# socket client
- C# Socket client server
- client server program in C#
- client server socket program in java
- client server sockets java
- java c# communication
- java C# socket communication
- Socket Programming in C#
- c# http client
- C# open socket
- c# server socket
- C# serversocket
- c# socket programming
- client server in c#
- client server socket program java
- java client c server
- socket between java and c#
- c# socket readline
- client server program C#

Aya said,
May 8, 2009 @ 10:51
Please , help me to write a program between server and client in two states : in same computer , with two different computers . . . . Thanks
Shaykh said,
June 10, 2009 @ 12:17
Article is good. However it looks like some kind of seo site. The main purpose is not solving some exact problem. BUt upgradeing the rating of site . It is seen like abc ..
Frank said,
October 17, 2009 @ 16:05
Hi,
at first, sorry for my english … i hope you will understand my problem
My java serversocket runs in a while(true) loop and listen at accept() the incomming .net clients. Each accepted client socket start a new thread. If only one client connect to the java socket server, all works nice, but if I use more than one client parallel, the second client will be blocked and I get the esception: A blocking operation was interrupted by a call to WSACancelBlockingCall
I thougt the problem is, that both clients (each came from an other pc with it’s own IP) like to comunicate over the same server socket port. Is this the reason? And how I can solve this.
Thanks for your help.
darkigo said,
March 16, 2010 @ 4:16
Ultra Helpful, thanks dude !