By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,891 Members | 1,255 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,891 IT Pros & Developers. It's quick & easy.

How can I call this?

P: n/a
How can I call this?
This doesn't work:
SendReceiveTest4();

public static int SendReceiveTest4(Socket server)
{
byte[] msg = Encoding.UTF8.GetBytes("This is a test");
byte[] bytes = new byte[256];
try
{
// Blocks until send returns.
int i = server.Send(msg, 0, msg.Length, SocketFlags.None);
Console.WriteLine("Sent {0} bytes.", i);

// Get reply from the server.
server.Receive(bytes, 0, server.Available, SocketFlags.None);
Console.WriteLine(Encoding.UTF8.GetString(bytes));
}
catch (SocketException e)
{
Console.WriteLine("{0} Error code: {1}.", e.Message,
e.ErrorCode);
return (e.ErrorCode);
}
return 0;
}

Thanks,
Trint

Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi,

You have to pass the Socet -
Socket mySocket = new Socket (...);
int retValue = SendReceiveTest4(mySocket);

--
Regards,
Peter Jausovec
(http://blog.jausovec.net)
"trint" <tr***********@gmail.com> je napisal v sporocilo
news:11*********************@l41g2000cwc.googlegro ups.com ...
How can I call this?
This doesn't work:
SendReceiveTest4();

public static int SendReceiveTest4(Socket server)
{
byte[] msg = Encoding.UTF8.GetBytes("This is a test");
byte[] bytes = new byte[256];
try
{
// Blocks until send returns.
int i = server.Send(msg, 0, msg.Length, SocketFlags.None);
Console.WriteLine("Sent {0} bytes.", i);

// Get reply from the server.
server.Receive(bytes, 0, server.Available, SocketFlags.None);
Console.WriteLine(Encoding.UTF8.GetString(bytes));
}
catch (SocketException e)
{
Console.WriteLine("{0} Error code: {1}.", e.Message,
e.ErrorCode);
return (e.ErrorCode);
}
return 0;
}

Thanks,
Trint

Nov 16 '05 #2

P: n/a
Peter,
Socket mySocket = new Socket (System.IntPtr.Zero);<<here
What do I put here (...)?
I get some type of error code no matter what I put:
"CS0122: 'System.Net.Sockets.Socket.Socket(System.IntPtr)' is
inaccessible due to its protection level."

Here is my code before that:
private void button12_Click(object sender, System.EventArgs e)
{
IPHostEntry ipHostInfo = Dns.Resolve("NPIFA21AE");
IPAddress ipAddress = ipHostInfo.AddressList[0];
IPEndPoint ipe = new IPEndPoint(ipAddress,515);
TcpClient s = new TcpClient();
//IPAddress Send = ipHostInfo.AddressList[0];

try
{
s.Connect(ipe);
}
catch(ArgumentNullException ae)
{
Console.WriteLine("ArgumentNullException : {0}", ae.ToString());
// listBox1.Items.Add("ArgumentNullException : {0}", ae.ToString());
}
catch(SocketException se)
{
Console.WriteLine("SocketException : {0}", se.ToString());
// listBox1.Items.Add("SocketException : {0}", se.ToString());
}
catch(Exception se)
{
Console.WriteLine("Unexpected exception : {0}", e.ToString());
// listBox1.Items.Add("Unexpected exception : {0}", e.ToString());
}
//
// byte[] msg = System.Text.Encoding.ASCII.GetBytes("This is a test");
// int bytesSent = s.Send(msg);
//
// byte[] bytes = new byte[1024];
// int bytesRec = s.Receive(bytes);
// Console.WriteLine("Echoed text = {0}",
// System.Text.Encoding.ASCII.GetString(bytes, 0, bytesRec));

Socket mySocket = new Socket (System.IntPtr.Zero);
int retValue = SendReceiveTest4(mySocket);
}
Thanks for any help,
Trint
.Net programmer
tr***********@gmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.