all groups > vj# > april 2005 >
You're in the

vj#

group:

Sending Message On A Network


Sending Message On A Network asilter
4/5/2005 6:25:01 AM
vj#:
Application.Run(..) code executed, the windows form was shown on the screen,
but after this,
codes below this expression does not execute(for example server= new
ServerSocket(15)).
The interesting one is; when i close the windows form compiler goes to this
line.

Why do i need to close the form to execute the lines after Application.Run()?
Already i need that form to be on screen at the same time when codes are
executing.

public static void main(String[] args)
{

try
{
Application.Run(new Form1());
server=new ServerSocket(15);
nextClient=server.accept();
txtConnection.set_Text("Kuruldu!");
}
catch (IOException ioe)
{
System.err.println ("Error " + ioe);
}
Re: Sending Message On A Network Lars-Inge Tønnessen [VJ# MVP]
4/5/2005 8:50:35 PM

You can't do that. You are running your code on the main thread. That means
the code is running in a sequence. Line 1 runs before line 2 and so on.
Please move your code to after the :

// TODO: Add any constructor code after InitializeComponent call



I would recommend a J# book:

http://www.microsoft.com/learning/books/devtools/vstudio.net/vjsharp.net/

http://www.microsoft.com/mspress/books/5834.asp


The example:


package WindowsApplication3;

import System.Drawing.*;
import System.Collections.*;
import System.ComponentModel.*;
import System.Windows.Forms.*;
import System.Data.*;

/**
* Summary description for Form1.
*/
public class Form1 extends System.Windows.Forms.Form
{
/**
* Required designer variable.
*/
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
// YOUR CODE HERE
server=new ServerSocket(15);
nextClient=server.accept();
txtConnection.set_Text("Kuruldu!");
}

/**
* Clean up any resources being used.
*/
protected void Dispose(boolean disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
super.Dispose(disposing);
}

#region Windows Form Designer generated code
/**
* Required method for Designer support - do not modify
* the contents of this method with the code editor.
*/
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.set_Size(new System.Drawing.Size(300,300));
this.set_Text("Form1");
}
#endregion

/**
* The main entry point for the application.
*/
/** @attribute System.STAThread() */
public static void main(String[] args)
{
Application.Run(new Form1());
}
}



Regards,
Lars-Inge Tønnessen

Re: Sending Message On A Network asilter
4/6/2005 11:49:03 AM
thinking the same example; suppose that both client and server windows forms
are on each of the screens, and the connection is established.

how will i trigger the client side, when i fill in a textfield and click on
the submit button on the server side? because client must get the
inputstream, how?

because both sides'
Application.Run(new Form1());
statement is the last working statement(forms are on the screen).


[quoted text, click to view]
Re: Sending Message On A Network Lars-Inge Tønnessen [VJ# MVP]
4/8/2005 12:00:00 AM

Please see if the code in the other thread solved it. =:o)


Best regards,
Lars-Inge Tønnessen

Re: Sending Message On A Network asilter
4/8/2005 12:11:01 PM
yes i know threads and you recommend me to use pipes between threads or
server/client role-changes to message eachother. yes, my application will do
simple messaging with server/client method. or i'm going on this way :)

but my problem definition went to a strange point. when i test my code on
two machines on the network. client-side connects to the server first. after
that server side sends the message with a textfield and a submit button.

when i execute the codes lien by line on the client side, and when

BufferedReader reader=new BufferedReader(new
InputStreamReader(client.getInputStream()));

object is created, i can see in the watch screen that reader.readLine()'s
value is the text which i sent from the server side. this is the expecting
case and normal. but after the line of reader creation, when i execute the
line below;

String alinanMesaj=reader.readLine();

alinanMesaj and reader.readLine() becomes null on the watch screen. i
couldn't and don't understand why it is happening.

Best regards,
asilter



[quoted text, click to view]
Re: Sending Message On A Network Lars-Inge Tønnessen [VJ# MVP]
4/8/2005 7:15:11 PM

Do you know threads?


[quoted text, click to view]

The server listens for clients. A client "drive" the connection cycle The
server will only handle requests from the client. Servers do not connect to
clients. There are no problem to first open a connection from a client to a
server and let them switch roles. You do that with a read/write protocol, or
by using two socket connections (one from the client to the server, and an
other from the server (that acts as a new client) to the client (that acts
as a server).


[quoted text, click to view]

For a socket code example please see one of my previous socket reply:

http://www.codecomments.com/forum295/message407079.html



[quoted text, click to view]

You should not do anything at all here.


The solution to a blocking socket connection and a user interface are
threads. The solution for the "Application.Run()" thing is also threads.
The question is, do you know what a thread is (I must know this before I can
provide more help) ?


Best regards,
Lars-Inge Tønnessen

AddThis Social Bookmark Button