HighTechTalks DotNet Forums  

Sending Message On A Network

Dotnet VJSharp microsoft.public.dotnet.vjsharp


Discuss Sending Message On A Network in the Dotnet VJSharp forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
asilter
 
Posts: n/a

Default Sending Message On A Network - 04-05-2005 , 09:25 AM






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);
}
}

Reply With Quote
  #2  
Old   
asilter
 
Posts: n/a

Default Re: Sending Message On A Network - 04-06-2005 , 02:49 PM






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).


"Lars-Inge Tønnessen [VJ# MVP]" wrote:

Quote:
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/bo...t/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




Reply With Quote
  #3  
Old   
asilter
 
Posts: n/a

Default Re: Sending Message On A Network - 04-08-2005 , 03:11 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



"Lars-Inge Tønnessen [VJ# MVP]" wrote:

Quote:
Do you know threads?


thinking the same example; suppose that both client and server windows
forms
are on each of the screens, and the connection is established.

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).


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?

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

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



Application.Run(new Form1());

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




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.