So, I'm having a problem with sending data from a C# client to a Java Server. The connection is going through, however I'm messing something up somewhere I guess.
Here's the ServerSided Code
package com.chris.net;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
public class Server implements Runnable
{
private String serverName;
private boolean isRunning;
private ServerSocket serverSocket;
private Socket clientSocket;
public Server(String name, int port)
{
try
{
this.serverName = name;
this.serverSocket = new ServerSocket(port);
this.isRunning = true;
new Thread(this).start();
}
catch (IOException e)
{
e.printStackTrace();
}
}
private BufferedReader recv;
public void run()
{
while(isRunning)
{
try
{
clientSocket = serverSocket.accept();
System.out.println("Client Connected from " + clientSocket.getInetAddress().getHostAddress() + ":" + clientSocket.getPort());
recv = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
System.out.println("Data Recieved: " + recv.readLine());
clientSocket.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
}
Here is the Client Code
lass TCPClient
{
private TcpClient Client;
private NetworkStream Stream;
private Byte[] Data;
public TCPClient(string address, int port)
{
Client = new TcpClient();
Client.Connect(address, port);
Stream = Client.GetStream();
SendData("Test Data");
while (Client.Connected)
{
}
}
public void SendData(string message)
{
Data = System.Text.Encoding.ASCII.GetBytes(message);
Stream.Write(Data, 0, Data.Length);
Console.WriteLine("Sent: {0}", message);
}
}
The server registers the connection, and the client seems to think that it has sent the data, however I can't tell if it's the Client not sending the Data or if it's the Server not receiving it. Considering the Console.Writeline is just printing out the message that was converted into bytes, I can't tell.