Winsock in C#

G

Guest

Does anybody know where i can get a winsock class for C#? badly needed. ANy
help would be very much appreciated. Thank you so so much!

-Stan
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

..NET has it own implementation of sockets , have you tried to use it?
Don;t know if you can use Raw sockets though, if ont you will have to
P/nvoke
 
K

Kevin Spencer

You can use raw Sockets in .Net. The Sockets classes are pretty darned
excellent!

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Development Numbskull

Abnormality is anything but average.
 
G

Guest

I know that there is an .NET implementation of sockets but i really need the
winsock. This is the case, im doing an activeX.. C# dll to be used on web...
so heres the problem, everything works fine with the dll and web until my dll
reaches tcpListener.Start(), it produces an exception.. something about
security and permissions. Ive tried solving it with other people's
suggestions like changing the assembly to fulltrust but it doesnt seem to
work. So now, i was thinking that maybe, just maybe winsock will be able to
do it.. so i need the class if any of you have it or the link... i would be
very much grateful.. or any suggestions or ideas at all.. thank you so much
 
D

dmm

What OS are you on? I ran into this once when I put some server code up on a
Windows Server 2003 box.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Rain said:
I know that there is an .NET implementation of sockets but i really need
the
winsock. This is the case, im doing an activeX.. C# dll to be used on
web...
so heres the problem, everything works fine with the dll and web until my
dll
reaches tcpListener.Start(), it produces an exception.. something about
security and permissions.

Maybe your problem is of security, most probably the user under which the
web app is running does not have access to open TCP connections.

What is the exception you are getting?

if you can post some code (in case it's relevant) do so as it can help
 
G

Guest

Thanks Ignacio, dmm and kevin for replying, makes me feel that theres hope
for this.. hehe Ive been working on these for 3 days now but still nothing.

Its definitely security problems and ive been changing the permissions to
fulltrust already, im not sure if im doing it wrong or it just doesn work. Im
using C# to make a DLL for my web application to use as an
object(ActiveX). Everything works fine until my dll starts to call the
tcplistener.Start(). It works fine when i test it as a console application
but when used as an activeX app in the web, it produces an SecurityException:

------------------------------------------------------------------------------
System.Security.SecurityException: Request for the permission of type
'System.Net.SocketPermission, System, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089' failed.

The action that failed was:
Demand
The type of the first permission that failed was:
System.Net.SocketPermission
The Zone of the assembly that failed was:
Intranet

---------------------------------------------------------------------------------

Heres the part of my code where it fails: (it works on console but doesnt on
activeX so i think nothings wrong with my code)

private void StartListen()
{
System.Windows.Forms.MessageBox.Show("StartListen");
while(_flagServer)
{
try
{
System.Windows.Forms.MessageBox.Show("while(_flagServer)");
Socket socket = _tcpListener.AcceptSocket();
socket.Blocking = true;

if(socket.Connected)
{
SocketProcessor processor = new SocketProcessor( socket );
processor.OnTerminate += new SocketProcessor.TerminateEventHandler(
this.OnTerminateHandler );
_processors.Add( processor );
Thread thread = new Thread( new ThreadStart( processor.Process ));
thread.Start();
}
}
catch (SocketException ex)
{
System.Windows.Forms.MessageBox.Show("SocketException: {0}", ex.ToString());
_flagServer = false;
break;
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show("Exception: {0}", ex.ToString());
_flagServer = false;
break;
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top