Click here to Skip to main content
15,902,112 members
Home / Discussions / C#
   

C#

 
GeneralRe: Program use frequency Pin
Freddie8318-Aug-04 21:22
Freddie8318-Aug-04 21:22 
GeneralRe: Program use frequency Pin
Nick Parker19-Aug-04 1:30
protectorNick Parker19-Aug-04 1:30 
GeneralRe: Program use frequency Pin
Freddie8319-Aug-04 21:56
Freddie8319-Aug-04 21:56 
QuestionHow to unzip .tar file? Pin
Nirmalan18-Aug-04 1:43
Nirmalan18-Aug-04 1:43 
AnswerRe: How to unzip .tar file? Pin
Nick Parker18-Aug-04 4:22
protectorNick Parker18-Aug-04 4:22 
QuestionHow can I open a VS.Net project remotely? Pin
mkomasi18-Aug-04 1:09
mkomasi18-Aug-04 1:09 
AnswerRe: How can I open a VS.Net project remotely? Pin
Sebastian Schneider18-Aug-04 1:30
Sebastian Schneider18-Aug-04 1:30 
GeneralNon-Blocking Server (asynchronous), need to pass data along -> Problem Pin
Sebastian Schneider18-Aug-04 1:04
Sebastian Schneider18-Aug-04 1:04 
Hello everyone,

I am currently developing an non-blocking server in C#. We opted for
implementation using asynchronous sockets.

The Server is based on Microsofts "non-blocking server" example, which can be found at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconnon-blockingserversocketexample.asp

Basically, my server is all the same.

Unfortunately, I need to read some account info (the server is acting as a bridge to another system) very early in the progress, which then has to be used by any "WorkerSocket".

I am reading this information in the main thread (called "StartListening" in the example) and storing it into an "AccountDataObject" which has room for the account data and one Socket.

It wont work. I can pass the object along with the "BeginAccept" of the socket, but will not be able to connect to the server with my client. Nontheless, if I do everything as in MS's example, it works.

Here is my code:

[code] ---- BEGIN CODE EXCERPT ----
public static void OpenListener()
{
int myport = 0;
AccountDataObject mySAPAccount = new AccountDataObject();
INIAccess.IniFile myIni = new INIAccess.IniFile();

myport = Convert.ToInt32(myIni.IniReadValue("System","Port"));

myAccount.host = myIni.IniReadValue("Remote","Host");
myAccount.uname = myIni.IniReadValue("Remote","Username");
myAccount.pword = myIni.IniReadValue("Remote","Password");

IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName());
IPAddress ipAddress = ipHostInfo.AddressList[0];
IPEndPoint localEndPoint = new IPEndPoint(ipAddress, myport);


myAccount.listenSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);


try
{
myAccount.listenSocket.Bind(localEndPoint);
myAccount.listenSocket.Listen(100);


while (true)
{
allDone.Reset();
myAccount.listenSocket.BeginAccept(new AsyncCallback(AcceptCallback), myAccount);
allDone.WaitOne();
}
}
catch(Exception e)
{
string test = e.ToString(); // INT *TO BE DONE*
}
finally
{ // INT *TO BE DONE*
}
}
[/code] ---- END CODE EXCERPT ----

The problem seems to be that - as opposed to microsofts example - i am working with my socket stored in an object.

Here are the first lines of the associated "Accept"-Callback:

[code] ---- BEGIN CODE EXCERPT ----
public static void AcceptCallback(IAsyncResult ar)
{
allDone.Set();
AccountDataObject myAccount = (AccountDataObject) ar.AsyncState;
Socket handler = myAccount.listenSocket.EndAccept(ar);
StateObject state = new StateObject();
state.workSocket = handler;
...
[/code] ---- END CODE EXCERPT ----

If I change everything back to Microsoft's Example - that is, doing everything with a "Listener"-Socket and only pass that socket along - it works perfectly.

That way, I would have to hard-code the account information into the program, which is not possible.

What should I do? I _have_ to read these values from an INI-File on startup, as they may be changed automatically by the tool which restarts the server every few hours. I totally depend on that INI-File for the Remote-System-Account Information.

Passing along information in "StateObjects" does work for the other asynchronous callbacks, though.

Thanks in Advance
Sebastian Schneider
GeneralSolution (Hint for all service programmers, maybe) Pin
Sebastian Schneider18-Aug-04 4:27
Sebastian Schneider18-Aug-04 4:27 
GeneralDataGrid Problem Pin
nnz17-Aug-04 21:59
nnz17-Aug-04 21:59 
GeneralRe: DataGrid Problem Pin
Syed Abdul Khader18-Aug-04 1:50
Syed Abdul Khader18-Aug-04 1:50 
GeneralSerialization Pin
Member 1697717-Aug-04 20:43
Member 1697717-Aug-04 20:43 
GeneralRe: Serialization Pin
Andreas X17-Aug-04 20:46
professionalAndreas X17-Aug-04 20:46 
GeneralRe: Serialization Pin
Member 1697717-Aug-04 21:07
Member 1697717-Aug-04 21:07 
GeneralRe: Serialization Pin
Nick Parker18-Aug-04 4:44
protectorNick Parker18-Aug-04 4:44 
Generalprogrammatically import and export data Pin
Stastlivec17-Aug-04 20:25
Stastlivec17-Aug-04 20:25 
Generalredistributing fonts Pin
Judah Gabriel Himango17-Aug-04 17:31
sponsorJudah Gabriel Himango17-Aug-04 17:31 
GeneralRe: redistributing fonts Pin
Dave Kreskowiak18-Aug-04 7:03
mveDave Kreskowiak18-Aug-04 7:03 
GeneralRe: redistributing fonts Pin
Judah Gabriel Himango18-Aug-04 8:34
sponsorJudah Gabriel Himango18-Aug-04 8:34 
QuestionIn GIF is Clearly then Out GIF,Why? Pin
Xytme17-Aug-04 16:56
Xytme17-Aug-04 16:56 
GeneralUsing MSDE in C# Pin
Christian Graus17-Aug-04 13:36
protectorChristian Graus17-Aug-04 13:36 
GeneralRe: Using MSDE in C# Pin
fayth17-Aug-04 14:55
fayth17-Aug-04 14:55 
GeneralRe: Using MSDE in C# Pin
S Sansanwal17-Aug-04 15:58
S Sansanwal17-Aug-04 15:58 
Generalsql packager/sql compare Pin
Irish_GUI17-Aug-04 12:18
Irish_GUI17-Aug-04 12:18 
GeneralEscape characters in text box Pin
BrcKcc17-Aug-04 11:38
BrcKcc17-Aug-04 11:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.