XML based message : Socket « Network Protocol « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » Network Protocol » SocketScreenshots 
XML based message
     


import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class SimpleSocketServer {

  public static void main(String args[]) throws Exception {
    ServerSocket serverSocket;
    int portNumber = 1777;
    Socket socket;
    String str;

    str = " <?xml version=\"1.0\" encoding=\"UTF-8\"?>";
    str += "<ticketRequest><customer custID=\"1\">";
    str += "</ticketRequest>";

    serverSocket = new ServerSocket(portNumber);

    System.out.println("Waiting for a connection on " + portNumber);

    socket = serverSocket.accept();

    ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());

    oos.writeObject(str);

    oos.close();

    socket.close();

  }

}





import java.io.ObjectInputStream;
import java.net.InetAddress;
import java.net.Socket;

public class SimpleSocketClient {

  public static void main(String args[]) throws Exception {
    Socket socket;
    int portNumber = 1777;
    String str = "";

    socket = new Socket(InetAddress.getLocalHost(), portNumber);

    ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
    str = (Stringois.readObject();
    System.out.println(str);
  }

}

   
    
    
    
    
  
Related examples in the same category
1. Create a socket without a timeout
2. Create a socket with a timeout
3. Demonstrate Sockets.
4. Socket connection and concurrent package
5. ObjectInputStream and ObjectOutputStream from Socket
6. ServerSocket and Socket for Serializable object
7. String based communication between Socket
8. Get email with Socket
9. Create PrintWriter from BufferedWriter, OutputStreamWriter and Socket
10. Read from server
11. Use Socket to read and write stream
12. Connects to a server at a specified host and port. It reads text from the console and sends it to the server
13. A simple network client that establishes a network connection to a specified port on a specified host, send an optional message across the connection
14. Reading Text from a Socket
15. Writing Text to a Socket
16. Sending a POST Request Using a Socket
17. Get the Date from server
18. Transfer a file via Socket
19. Ping a server
20. Read and write through socket
21. Read float number from a Socket
22. Read Object from Socket
23. deleting messages from a POP3 mailbox based on message size and Subject line
24. A timeout feature on socket connections
25. Write Objects From Socket
26. Write Double Using Sockets
27. Download WWW Page
28. Redirects incoming TCP connections to other hosts/ports
29. Socket Fetcher
30. Socket Address Encoder
31. Zip socket
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.