Click here to Skip to main content
15,890,336 members
Home / Discussions / C#
   

C#

 
AnswerRe: Sockets: Send strings from Java to C#? Pin
Luc Pattyn13-May-11 16:35
sitebuilderLuc Pattyn13-May-11 16:35 
GeneralRe: Sockets: Send strings from Java to C#? Pin
Daniel Scott13-May-11 23:43
Daniel Scott13-May-11 23:43 
GeneralRe: Sockets: Send strings from Java to C#? Pin
Mark Salsbery13-May-11 18:11
Mark Salsbery13-May-11 18:11 
GeneralRe: Sockets: Send strings from Java to C#? Pin
Richard MacCutchan13-May-11 22:12
mveRichard MacCutchan13-May-11 22:12 
GeneralRe: Sockets: Send strings from Java to C#? Pin
Mark Salsbery13-May-11 22:20
Mark Salsbery13-May-11 22:20 
GeneralRe: Sockets: Send strings from Java to C#? Pin
Richard MacCutchan13-May-11 23:33
mveRichard MacCutchan13-May-11 23:33 
AnswerRe: Sockets: Send strings from Java to C#? Pin
CodeGust15-May-11 19:19
CodeGust15-May-11 19:19 
AnswerRe: Sockets: Send strings from Java to C#? Pin
CodeGust16-May-11 14:53
CodeGust16-May-11 14:53 
Thank everyone for trying to help! I think I've found a good, working solution. Using UDP sockets:

Java code:
         public void runJavaSocket() {
		System.out.println("Java Sockets Program has started."); int i=0;

		try {
			DatagramSocket socket = new DatagramSocket();
			System.out.println("Sending the udp socket...");
	        // Send the Message "HI"
	        socket.send(toDatagram("HI",InetAddress.getByName("127.0.0.1"),3800));
        	while (true)
        	{
	        	System.out.println("Sending hi " + i);
				Thread.currentThread();
				Thread.sleep(1000);
				socket.send(toDatagram("HI " + String.valueOf(i),InetAddress.getByName("127.0.0.1"),3800));
				i++;
        	}
		} catch (Exception e) {
			e.printStackTrace();
		}
}
	public DatagramPacket toDatagram(
			  String s, InetAddress destIA, int destPort) {
		// Deprecated in Java 1.1, but it works:
		byte[] buf = new byte[s.length() + 1];
		s.getBytes(0, s.length(), buf, 0);
		// The correct Java 1.1 approach, but it's
		// Broken (it truncates the String):
		// byte[] buf = s.getBytes();
		return new DatagramPacket(buf, buf.length, 
		destIA, destPort);
		}

C# code:
string returnData;
byte[] receiveBytes;
//ConsoleKeyInfo cki = new ConsoleKeyInfo();

using (UdpClient udpClient = new UdpClient(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 3800)))
{
    IPEndPoint remoteIpEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 3800);
    while (true)
    {
        receiveBytes = udpClient.Receive(ref remoteIpEndPoint);
        returnData = Encoding.ASCII.GetString(receiveBytes);
        Console.WriteLine(returnData);
    }
}

QuestionOutput HTML table from XML file Pin
rolandvink13-May-11 11:45
rolandvink13-May-11 11:45 
AnswerRe: Output HTML table from XML file Pin
jschell13-May-11 12:25
jschell13-May-11 12:25 
GeneralRe: Output HTML table from XML file Pin
AspDotNetDev13-May-11 12:51
protectorAspDotNetDev13-May-11 12:51 
GeneralRe: Output HTML table from XML file Pin
jschell13-May-11 12:57
jschell13-May-11 12:57 
AnswerRe: Output HTML table from XML file Pin
DaveAuld13-May-11 22:50
professionalDaveAuld13-May-11 22:50 
AnswerRe: Output HTML table from XML file Pin
RaviRanjanKr16-May-11 4:37
professionalRaviRanjanKr16-May-11 4:37 
Questionsend fax with C# 2010 [modified] Pin
esialex13-May-11 2:41
esialex13-May-11 2:41 
AnswerRe: send fax with C# 2010 Pin
_Erik_13-May-11 4:19
_Erik_13-May-11 4:19 
GeneralFaxcomexlib Pin
fbova30-May-11 11:00
fbova30-May-11 11:00 
GeneralRe: Faxcomexlib Pin
_Erik_31-May-11 2:54
_Erik_31-May-11 2:54 
Questionget invalid handle when called GetWindowLong. Pin
prasadbuddhika12-May-11 23:59
prasadbuddhika12-May-11 23:59 
AnswerRe: get invalid handle when called GetWindowLong. Pin
Luc Pattyn13-May-11 1:36
sitebuilderLuc Pattyn13-May-11 1:36 
GeneralRe: get invalid handle when called GetWindowLong. Pin
prasadbuddhika13-May-11 2:21
prasadbuddhika13-May-11 2:21 
AnswerRe: get invalid handle when called GetWindowLong. Pin
Luc Pattyn13-May-11 2:39
sitebuilderLuc Pattyn13-May-11 2:39 
GeneralRe: get invalid handle when called GetWindowLong. Pin
Dave Kreskowiak13-May-11 3:33
mveDave Kreskowiak13-May-11 3:33 
QuestionProblem matching name using Regex Pin
Etienne_12312-May-11 22:54
Etienne_12312-May-11 22:54 
AnswerRe: Problem matching name using Regex Pin
dasblinkenlight13-May-11 0:07
dasblinkenlight13-May-11 0:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.