473,732 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem connecting to a Server in C# from client in VC++

Hi

I'm having problem with a scenarion where I have a server written in C# and
client written in VC6++.

Here is the server code that i'm using including the Callback function for
handling clients. Also there's a commented code where i'm using TCPListener
instead of simple Socket Class. The problem i'm having is that when I run
this code using Socket class, the server starts well but "OnClientConnec t"
method never gets called. On debugging I found out that on the (VC++) client
side the socket connects successfully and even sends data successfully on
this connected socket. But on this C# server side the OnClientConnect
method never gets called. I dont know who's accepting the client.

On the contrary when I comment out this Socket code and uncomment the
TCPListener code, then the code gets executed as soon as the VC6 client
executes its "connect" call. Can someone please tell where could the problem
be with using Socket class in this server code, I'm really stuck in it.

Regards

Usman
////////////////////////////////////////////////////////////////////////////
/////////////////////////
int nServerPort = 0;
try
{

// Create the listening socket...
m_mainSocket = new Socket(AddressF amily.InterNetw ork,
SocketType.Stre am,
ProtocolType.Tc p);

IPHostEntry hostEntry = Dns.Resolve(szI PAddress);
IPAddress ipAddress = hostEntry.Addre ssList[0];

IPEndPoint ipLocal = new IPEndPoint (ipAddress, nServerPort);
// Bind to local IP Address...
m_mainSocket.Bi nd( ipLocal );

//IP Endpoint must be populated. Get the port
ipLocal = (IPEndPoint) m_mainSocket.Lo calEndPoint;

nServerPort = ipLocal.Port;

// Start listening...
m_mainSocket.Li sten (4);
// Create the call back for any client connections...
m_mainSocket.Be ginAccept(new AsyncCallback (OnClientConnec t), null);

/* USING TCPLISTENER
IPHostEntry hostEntry = Dns.Resolve(szI PAddress);
IPAddress ipAddress = hostEntry.Addre ssList[0];
TcpListener tcpListener = new TcpListener(ipA ddress, 33333);
tcpListener.Sta rt();

for(;;)
{
Socket socketForClient =tcpListener.Ac ceptSocket();
if(socketForCli ent.Connected)
{
Console.WriteLi ne("Client connected");
}
}
*/

}
catch(SocketExc eption se)
{
//Exception
}
return nServerPort;

////////////////////////////////////////////////////////////////////////////
/////////////////
OnClientConnect Function
////////////////////////////////////////////////////////////////////////////
/////////////////

public void OnClientConnect (IAsyncResult asyn)
{
try
{
// Here we complete/end the BeginAccept() asynchronous call
// by calling EndAccept() - which returns the reference to
// a new Socket object
Socket workerSocket = m_mainSocket.En dAccept (asyn);

// Let the worker Socket do the further processing for the connected
client

//Close the socket
workerSocket.Sh utdown(SocketSh utdown.Both);
workerSocket.Cl ose();

//Transfer is complete. close the server socket
m_mainSocket.Cl ose();
}
catch(ObjectDis posedException)
{
//System.Diagnost ics.Debugger.Lo g(0,"1","\n OnClientConnect ion: Socket
has been closed\n");
}
catch(SocketExc eption se)
{
//MessageBox.Show ( se.Message );
}

}
Nov 23 '05 #1
0 1461

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2545
by: Ali | last post by:
I'm trying to write a really basic chat program that allows 2 client programs to send messages to each other via a server. I've managed to write the code so that both clients can connect to the server and send and recieve messages to/from the server but when I send a message from one client I can't get the message to appear in the second client. I think it's something to do with threads but I don't know what! I've been looking at the...
1
3790
by: Dmitry Akselrod | last post by:
Hello everyone, I have a vb.net application that wraps the TCPListener object in a class. The server connects to the local interface and establishes itself on port 9900. It then polls for pending connections every 500ms. I also have a vb6 application that uses the WinSock control at the other end of the communication tunel. I have to work with vb6 here because it uses less memory than .NET.
0
1918
by: richard | last post by:
OS: Winxp and Win2003 Visual Basic.NET 2003 MS-SQL Server 2000 hey all I am a newbie in vb.net but i have managed to build a simple chat server in vb.net using socket and a client connecting to it made in vb6. Some of the code in the server are based on the basic samples that i get from other authors. To give you an idea, the server uses sockets,
1
2087
by: Thomee Wright | last post by:
I'm having a problem with a pair of applications I'm developing. I have a server application which interacts with several instruments, and a client app which connects to the server and provides a UI for interacting with the instruments. Readings from the instruments are periodically sent to the clients, and clients will send commands to the server based on user input. In normal usage there will be around 6 clients connected, with a...
0
3921
by: Suresh | last post by:
Hi Guys I have Db2 server installed on remote server. i am connecting to that remote server by using VPN. I want to connect that remote DB2 server instance using my local machine DB2 development client. Bur Its gives me following error message. I searched lots of things on net and tried on remote server but i didnt got suceess. Can any one tell me how to set TCP\IP connection protocol on server for particular instance. Becuase I think
5
24012
by: Suresh | last post by:
Hi Guys I have Db2 server installed on remote server. i am connecting to that remote server by using VPN. I want to connect that remote DB2 server instance using my local machine DB2 development client. Bur Its gives me following error message. I searched lots of things on net and tried on remote server but i didnt got suceess. Can any one tell me how to set TCP\IP
0
2867
by: NoaGross | last post by:
Hi, I'm relly new in java and I have a problem. I'm using java applet. When using http all ok, but when trying to use https i get: Java Plug-in 1.5.0_10 Using JRE version 1.5.0_10 Java HotSpot(TM) Client VM User home directory = C:\Documents and Settings\noa ---------------------------------------------------- c: clear console window
9
4303
by: darthghandi | last post by:
I am trying to create a server application using asynchronous sockets. I run into a problem when I try to connect to my server using a non-.net program. I can establish the connection, and send some packets in response to the programs first message, but when I receive a response back, it's the last packet I sent. After that packet, I receive the packet I really wanted. This only happens when I connect with local host. I tried...
10
15952
by: mairhtin o'feannag | last post by:
Hello, I'm having problems connecting to my new v9 db box. The pertinent information is below: DB2_db2inst1 60000/tcp DB2_db2inst1_1 60001/tcp DB2_db2inst1_2 60002/tcp DB2_db2inst1_END 60003/tcp
0
8773
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9306
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9234
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6733
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4548
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4805
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3259
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2177
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.