LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-26-2005, 07:43 AM   #1
mrobertson
Member
 
Registered: May 2005
Posts: 275

Rep: Reputation: 30
C# Server Program not advancing through functions


I am currently writing a server program in visual c#. Her is a copy of my first two functions.

public void Form1_Load(object sender, System.EventArgs e)
{

IPEndPoint ipLocal = new IPEndPoint ( IPAddress.Any ,10119);
//bind to local IP Address...
myServer.Bind( ipLocal );
//start listening...
myServer.Listen(10);
sServerMsg = "Listening to port: ";
List1.Items.Add(sServerMsg);

}

public void OnClientConnect(IAsyncResult asyn)
{

myServer.Close();
myServer.Accept();
sServerMsg = "Serving client!";
List1.Items.Add(sServerMsg);
}

My program never gets to the OnClientConnect function and when I put a breakpoint in that function I got a message that says:
Breakppoint will not currently be hit. No executable code associated with this line. how do I get my program to move onto this function and the functions following?
 
Old 05-26-2005, 12:53 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 05-26-2005, 01:28 PM   #3
towlie
Member
 
Registered: Apr 2004
Location: U.S.
Distribution: slackware 10.0
Posts: 110

Rep: Reputation: 15
You should probably post your entire source file, or at least the
parts you think are executable.

Probably you call that function from an event which you think is
being triggered but really isn't.

What does it do if you print "hello going into func" before the call
and "hello returned from func" after call?
 
Old 05-26-2005, 01:33 PM   #4
mrobertson
Member
 
Registered: May 2005
Posts: 275

Original Poster
Rep: Reputation: 30
public void Form1_Load(object sender, System.EventArgs e)
{

//nConnected = wsTCP.Connect("127.0.0.1", 10119);
IPEndPoint ipLocal = new IPEndPoint ( IPAddress.Any ,10119);
//bind to local IP Address...
myServer.Bind( ipLocal );
//start listening...
myServer.Listen(10);
sServerMsg = "Listening to port: ";
List1.Items.Add(sServerMsg);

}

public void OnClientConnect(IAsyncResult asyn)
{

//long requestID = _e1.requestID;
// the winsock control has to be in a closed state
// before it can do anything else. (like accept a connection)
//Winsock1[Index].Close();
// Let the winsock close
//System.Windows.Forms.Application.DoEvents();
// accept the connection request
// Winsock1[Index].Accept((int)(requestID));
// Define the message and display it in the list box

//myServer.Close();
myServer.Accept();
sServerMsg = "Serving client!";
List1.Items.Add(sServerMsg);
}

public void WaitForData(System.Net.Sockets.Socket soc)
{
// When the other end has closed the connection,
// close server end too

//Winsock1[Index].Close();
myServer.Close();
// to continue listening for another connection
//Winsock1[Index].Listen();
myServer.Listen(1000);
// show the connection in the list box
sServerMsg = "Listening to port: ";
List1.Items.Add(sServerMsg);
}


public void OnDataReceived(IAsyncResult asyn)
{
//int Index = Winsock1.GetIndex((AxMSWinsockLib.AxWinsock)_sender);
//long bytesTotal = _e1.bytesTotal;
string strTemp = String.Empty;
int a = 0;
// Dim strTemp2 As String
// This event fires when the process on the other end of the connection(i.e the client)
// sends data
// retreive data from socket

//strTemp = wsTCP.GetData();
// Winsock1(Index).GetData(strTemp, null, null);
// Winsock1(Index).GetData strTemp2
// The following code separates each part of the string based on the comma
// that is present in the incoming string and parses it out into its
// respective textbox
a = Strings.InStr(1, strTemp, ",", CompareMethod.Binary);
txtcoilid.Text = strTemp.Substring(0, a - 1);
// after the first parse you must refine the string as everthing after the comma and
// repeat the process throughout the entire string
strTemp = strTemp.Substring(a + 1- 1);
a = Strings.InStr(1, strTemp, ",", CompareMethod.Binary);
txtwidth.Text = strTemp.Substring(0, a - 1);
strTemp = strTemp.Substring(a + 1- 1);
a = Strings.InStr(1, strTemp, ",", CompareMethod.Binary);
txtlinespeed.Text = strTemp.Substring(0, a - 1);
strTemp = strTemp.Substring(a + 1- 1);
a = Strings.InStr(1, strTemp, ",", CompareMethod.Binary);
txtexitcoillength.Text = strTemp.Substring(0, a - 1);
}

Here is all of my code. It will execute the load form1 function but not any of the three after that. What do you mean by :

What does it do if you print "hello going into func" before the call
and "hello returned from func" after call?

What calls are you talking about? I llok forward to hearing back form you and thanks for your interest in helping me out.
 
Old 05-26-2005, 01:39 PM   #5
towlie
Member
 
Registered: Apr 2004
Location: U.S.
Distribution: slackware 10.0
Posts: 110

Rep: Reputation: 15
Oh, so OnClientConnect() is an event handler, right?

I thought you meant you were calling that function, but if
the system is supposed to call it for you, then I have no
idea where the problem would be.

I'd suggest you read whatever docs you have for that
event, might also check in the form designer on whether
that event registered (I'm not sure what object it would
be registered to).
 
Old 05-26-2005, 01:57 PM   #6
mrobertson
Member
 
Registered: May 2005
Posts: 275

Original Poster
Rep: Reputation: 30
Do you have any idea why the program would not just continue reading on down through the rest of the code. I am fairly new to C#. Where and how would I read up on something like this. I am using just a basic socket and I know that this is one of its functions. Why does the program stop reading code after the load form1 function?......Any ideas?......Again thanks for your help.
 
Old 05-26-2005, 02:09 PM   #7
towlie
Member
 
Registered: Apr 2004
Location: U.S.
Distribution: slackware 10.0
Posts: 110

Rep: Reputation: 15
Well, the program doesn't just start reading at the top, at least
not in C#. It usually starts at a function called main.

If you start in the form designer, it should create an empty function
called main() for you. From there you call the functions you want.

If this is code in a class that is inherited from another socket class,
then it just means the parent class isn't calling the function, and
maybe you expect it is but it isn't. What is the socket you're talking about?
 
Old 05-27-2005, 07:15 AM   #8
mrobertson
Member
 
Registered: May 2005
Posts: 275

Original Poster
Rep: Reputation: 30
I am sorry to keep bothering you but I think I am a bit confused. I am using a socket from the System.Net.Sockets.Socket class that implements the brekeley sockets interface. Is there some type of component that needs to be added to the for to initialize the functions that will not run? I know in vb6 and vb.net you have to add the socket(ususally winsock) to the form. If not, why would the parent class not call these functions?
 
Old 05-27-2005, 08:40 AM   #9
towlie
Member
 
Registered: Apr 2004
Location: U.S.
Distribution: slackware 10.0
Posts: 110

Rep: Reputation: 15
Some components in C# you use by dragging them onto the
form, and others you don't.

Unfortunately, I don't know enough about C# to be able to help
you much.

You might google for something like:
System.Net.Sockets.Socket tutorial

and see if you can get a step-by-step tutorial to do that.
Maybe it'll have pictures you can look at to see what to do.

btw, if you know how to do it in vb6, you might try doing
it in vb.net, since all the .net languages can communicate
with each other. Don't remeber how that's done either, but
that's really all I can tell you about C#.
 
Old 05-27-2005, 09:26 AM   #10
mrobertson
Member
 
Registered: May 2005
Posts: 275

Original Poster
Rep: Reputation: 30
I really appreciate all of the help that you have given me. Luckily I found what the problem was. In my load function, I need a call to the connect function to initialize a connection. I have one last question that is the only remaining problem that I am having. The following code is the problem:


System.String strTemp = new System.String(chars);
WaitForData(m_socWorker );
int a = 0;

a = Strings.InStr(1, strTemp, ",", CompareMethod.Binary);
txtcoilid.Text = strTemp.Substring(0, a - 1);

strTemp = strTemp.Substring(a + 1- 1);
a = Strings.InStr(1, strTemp, ",", CompareMethod.Binary);
txtwidth.Text = strTemp.Substring(0, a - 1);
strTemp = strTemp.Substring(a + 1- 1);
a = Strings.InStr(1, strTemp, ",", CompareMethod.Binary);
txtlinespeed.Text = strTemp.Substring(0, a - 1);
strTemp = strTemp.Substring(a + 1- 1);
a = Strings.InStr(1, strTemp, ",", CompareMethod.Binary);
txtexitcoillength.Text = strTemp.Substring(0, a - 1);


This code comes from my on data recieved function. My strTemp string should pass 4 variables that are separated by a comma. I am trying to look for the comma and place each value into a text box based on where the comma is located. The problem is My string is not being passed. Do you know what may cause this? Also when and if I get this code to work......will I be able to re type it in a text editor for linux and run the program with the same functionality(i.e. recieve a string of four variable). Will I need to change anything?
 
Old 05-27-2005, 10:05 AM   #11
towlie
Member
 
Registered: Apr 2004
Location: U.S.
Distribution: slackware 10.0
Posts: 110

Rep: Reputation: 15
Quote:
The problem is My string is not being passed.
Can't really say, I don't have access to C# anymore, so everything
I'm telling you is remembered from about a year ago. Maybe you
could print out the string to see what it's set to at different points
in the program. Just backtrack til you find the problem.

Also you might want to look into C#'s regular expression classes.
Might make it easier, or you may not like them, just a suggestion.


Quote:
Also when and if I get this code to work......will I be able to re type it in a text editor for linux and run the program with the same functionality(i.e. recieve a string of four variable). Will I need to change anything?
AFAIK, there's no way to get C# code to compile on anything but microsoft
sytems. You may be able to get a C# to C translator though, not really
sure. If your goal is portability you should probably be using either
Java, or PHP.
 
Old 05-27-2005, 10:22 AM   #12
mrobertson
Member
 
Registered: May 2005
Posts: 275

Original Poster
Rep: Reputation: 30
What about using visual c++ and creating a console application? If I wrote the code this way would I be able to compile the code in linux?
 
Old 05-27-2005, 10:23 AM   #13
mrobertson
Member
 
Registered: May 2005
Posts: 275

Original Poster
Rep: Reputation: 30
If so should it be a console app or a win32 app?
 
Old 05-27-2005, 10:54 AM   #14
towlie
Member
 
Registered: Apr 2004
Location: U.S.
Distribution: slackware 10.0
Posts: 110

Rep: Reputation: 15
C and C++ are portable between os's depending on what libraries you're
using. If it's just the more generic stuff like stdio library or the math library,
you can probably compile it on linux.

You said you need networking right. I'm almost positive that kind of code won't
work on both windows and linux. Because on windows, you're using windows
libraries with all of their functions, and the linux libraries have totally different
functions. So the networking part you'd have to write all over again.

If you need portable networking code, Java is the only language I know
of that might work. Not my favorite language for lot's of reasons, but I if I remember
right, the networking classes work across os's.


Many times when people write networking apps, they only write it for
a particular os. Why do you need it to work on windows and linux?

Last edited by towlie; 05-27-2005 at 10:56 AM.
 
Old 05-27-2005, 10:59 AM   #15
towlie
Member
 
Registered: Apr 2004
Location: U.S.
Distribution: slackware 10.0
Posts: 110

Rep: Reputation: 15
btw, don't know how much you need the networking stuff, but
if you build a win32 app it won't work in linux. Because you'd
be using the win32 gui libraries (same reason as I said before
with the networking).

Code written for visual c++ console apps goes back to what I said
before, if it just uses generic libraries it will be pretty much portable,
but it sounds like you need more than that.
 
  


Reply



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

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting php5 socket functions to php3 socket functions mrobertson Programming 0 06-23-2005 09:11 AM
time functions in a c program mbacke Programming 3 04-18-2005 02:42 PM
Calling User-space program functions from Kernel modules shivanu Programming 1 03-05-2005 02:11 PM
The impact of rapidly advancing technology on society carrja99 General 4 03-31-2003 09:09 AM
pointers to functions/member functions champ Programming 2 03-28-2003 06:22 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration