Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can anybody help me with this here.  I am working on a network application where I have to create a socket connection to the IP address and port that they already given me and then send XML message to the socket and finally include the ReadMe.txt file where I will save what I have received from the server
<pre>Send the following XML message to the socket, Please note there is no security, no certificates, just a plan TCP/IP connection. The
request message is formatted below. Please include a README.txt file where you saved what you have received from the server.
Without this file, your assignment will not be evaluated.
<request>
<EventType>Authentication</EventType>
<event>
<UserPin>12345</UserPin>
<DeviceId>12345</DeviceId>
<DeviceSer>ABCDE</DeviceSer>
<DeviceVer>ABCDE</DeviceVer>
<TransType>Users</TransType>
</event>
</request>



What I have tried:

private static Socket socket;

public static void main(String args[])
{
    try
    {
        socket = new Socket( "196.37.22.179", 9011);

        //Send the message to the server
        //PrintStream outstrm = null;
        OutputStream os = socket.getOutputStream();
        OutputStreamWriter osw = new OutputStreamWriter(os);
        BufferedWriter bw = new BufferedWriter(osw);

        String str;
        str = "<request>";
        str += "<EventType>Authentication</EventType>";
        str += "<event>";
        str += "<UserPin>12345</UserPin>";
        str += "<DeviceId>12345</DeviceId>";
        str += "<DeviceSer>ABCDE</DeviceSer>";
        str += "<DeviceVer>ABCDE</DeviceVer>";
        str += "<TransType>Users</TransType>";
        str += "</event></request>";
        bw.write(str);
        bw.flush();
        System.out.println("Message sent to the server......! ");

        //Get the return message from the server
        InputStream is = socket.getInputStream();
        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader br = new BufferedReader(isr);        
    }
    catch (Exception exception)
    {
        exception.printStackTrace();
    }
    finally
    {
        //Closing the socket
        try
        {
            socket.close();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
}
Posted
Updated 18-Sep-17 8:05am
Comments
OriginalGriff 18-Sep-17 12:21pm    
And?
What is the problem?
Where are you stuck?
What help do you need?
Samkelo Siyabonga Ngubo 18-Sep-17 12:24pm    
I want to read from README.txt file to store results from server in a file
Kevin Marois 18-Sep-17 12:51pm    
Look at StreamWriter

1 solution

Quote:
I want to read from README.txt file to store results from server in a file

C#
string text = File.ReadAllText(path);
Or
C#
string[] lines = File.ReadAllLines(path);

To add data to the file is just as simple:
C#
File.AppendAllText(path, data);
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900