When you have setup code for client application, after a connection is established, a server application uses the same kind of Socket object for its side of the communications. However, to accept a connection from a client, it must first create a ServerSocket, bound to the correct port. Let's recreate the previous conversation from the server's point of view:
Class library Socket Programming and Tutorial C# .NET and Java
Showing posts with label synchronous. Show all posts
Showing posts with label synchronous. Show all posts
Thursday, April 21, 2011
Tutorial Synchronous Socket Programming using JAVA (For Client)
A client application opens a connection to a server by constructing a Socket that specifies the hostname and port number of the desired server:
try { Socket sock = new Socket("wupost.wustl.edu", 25); } catch ( UnknownHostException e ) { System.out.println("Can't find host."); } catch ( IOException e ) { System.out.println("Error connecting to host."); }
Tutorial Synchronous Socket Programming using .NET (For Server)
The following example program creates a server that receives connection requests from clients. The server is built with a synchronous socket, so execution of the server application is suspended while it waits for a connection from a client. The application receives a string from the client, displays the string on the console, and then echoes the string back to the client. The string from the client must contain the string "<EOF>" to signal the end of the message.
Wednesday, April 20, 2011
Tutorial Synchronous Socket Programming using .NET (For Client)
The following example program creates a client that connects to a server. The client is built with a synchronous socket, so execution of the client application is suspended until the server returns a response. The application sends a string to the server and then displays the string returned by the server on the console.
CODE FOR VB
Imports System Imports System.Net Imports System.Net.Sockets Imports System.Text
Subscribe to:
Posts (Atom)