|
hi i am currently doing remoting in c#.net window application my server codes is below
i would like to ask if there i can put an event handler (function)
which will execute when there is an incoming request from the client
reason: as i need to reload the form when also populate one of the text box in the form when the request comes in
thx for reading
and hope you can help me pls
using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
using System.Runtime.Remoting;<br />
using System.Runtime.Remoting.Channels;<br />
using System.Runtime.Remoting.Channels.Tcp;<br />
<br />
namespace WindowsApplication2<br />
{<br />
public partial class Form1 : Form<br />
{<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
}<br />
<br />
private void Form1_Load(object sender, EventArgs e)<br />
{<br />
TcpChannel channel = new TcpChannel(8080);<br />
ChannelServices.RegisterChannel(channel);<br />
<br />
RemotingConfiguration.RegisterWellKnownServiceType(<br />
typeof(ClassLibrary1.Class1),<br />
"HelloWorld",<br />
WellKnownObjectMode.SingleCall);<br />
}<br />
}<br />
}
|
|
|
|
|
I too am trying to work out how to do this.
What I know so far is that you need to use
WellKnownObjectMode.Singleton
When registering, this means that the server maintains 1 instance of the object and gives a reference (proxy) to this each time a client asks for it.
However How do we instantiate and get a reference to this object on the server side? so we can see the data its fields contain etc...
(Also remoting is not thread safe, AFAIK each remote call executes on an individual thread so you need to make them thread-safe).
Wilco
|
|
|
|
|
Hi
I have a problem with changing printer's paper size to custom paper size(programmatically).
I use PaperSize cunstuctor to create custom paper size and then assign it to PrintDocument.DefaultPageSettings.PaperSize.
this is not change paper size in printer.
Dim pd As PrintDocument = New PrintDocument
Dim pkCustomSize1 As New PaperSize("Custom", 100, 200)
pd.DefaultPageSettings.PaperSize = pkCustomSize1
Please Guide me
Thnaks
|
|
|
|
|
hi i am trying to do remoting so far i am able to connect but i cant seem to pass any data thru my code is as fellows:
i would too like to ask if my code is passing data from the sever to client or vise versa as i am a little confuse.
my server:
TcpChannel channel = new TcpChannel(8080);<br />
ChannelServices.RegisterChannel(channel);<br />
<br />
RemotingConfiguration.RegisterWellKnownServiceType(<br />
typeof(ClassLibrary1.Class1),<br />
"HelloWorld",<br />
WellKnownObjectMode.SingleCall);
my client:
TcpChannel chan = new TcpChannel();<br />
ChannelServices.RegisterChannel(chan);<br />
<br />
ClassLibrary1.Class1 obj = (ClassLibrary1.Class1)Activator.GetObject(<br />
typeof(ClassLibrary1.Class1),<br />
"tcp://172.17.168.51:8080/HelloWorld");<br />
<br />
try<br />
{<br />
if (obj.Equals(null))<br />
{<br />
label1.Text = "not connected";<br />
}<br />
else<br />
{<br />
label1.Text = "connected";<br />
}<br />
}<br />
catch<br />
{<br />
label1.Text = "not connected";<br />
}
my class:
public class Class1 : MarshalByRefObject<br />
{<br />
<br />
public Class1()<br />
{<br />
string abc; <br />
}<br />
<br />
<br />
<br />
<br />
}
as you can see my class contint a string abc i would like to ask how can i set it at my start and what code would i use to exttract it at the end side
|
|
|
|
|
Hi all..
Can anyone provide me with the code convertor tool...ie.the tool which converts the vb.net code to C# code and vice versa...
It would be better if the tool is an .exe..
Some one help in this regard as early as possible...
Note:Dont reply asking to try in google...
Regards,
Balaguru
|
|
|
|
|
Hi Balaguru,
First of all this is no service that you can get from this web site, that you can command for information. All you can do is to request for information, and be polite.
If somebody asks you to try in Google, it may be because its an obvious information. What you have asked here now is such a question. Code convertor tools are available in plenty and all you got to do is use google to find it. Forget google my friend, its available here in Code project.
http://www.codeproject.com/csharp/gbvb.asp
So first try some resources and only if you dont find any usefull information, post it here.
In my case, I dont have access to Google in my work place, still I post questions only after going through articles here. I do not mean any offence, but I hope many of our members would agree with me.
Regards,
Blumen
|
|
|
|
|
Hi Blumen...
I feel sorry if my post has insulted u...I dont find any commanding issues in my post rather i have made only a humble request..As like u i too dont have access to google in my office.Thats wat made me to make a note in my post.What happens is that we post a question and long for replies.If the reply simply comes try in google,its very irritating..Thats it..
Anyway i am sorry ...
Regards,
Balaguru
|
|
|
|
|
Balagurunathan S wrote: As like u i too dont have access to google in my office.
You need to make this clear. It's about the dumbest policy I ever heard of, so you're going to have to tell us that it's the case where you are.
http://www.tangiblesoftwaresolutions.com[^] is one of the hits I got with google.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi,
Your words dint insult me, I found it impolite, though. Anyways I hope you would have got useful information regarding the tool now. Try these as well:
http://www.developerfusion.co.uk/utilities/convertvbtocsharp.aspx
http://www.kamalpatel.net/ConvertCSharp2VB.aspx
Regards,
Blumen
|
|
|
|
|
Balagurunathan S wrote: Note:Dont reply asking to try in google...
So why is Google blocked at your workplace?
Yahoo too?
Seriously, all you had to do was type "vb.net c# converter" into either one and you'd come up with a bunch of them.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Hi Dave,
I've no idea why Google is blocked here, thank god we have access to CP
Yahoo is not blocked, we can use Yahoo search, but can't open any results because those websites would be blocked. I believe they are restricting Internet access to maintain safety of the code and of the network, from hacks and viruses. We can't access any personal e-mail, i.e. websites like Yahoomail, hotmail, gmail etc.
I don't think situation is the same in all companies here, some companies give unrestricted access to its employees.
From which part of the world are you from Dave, and how is network maintained in your company? I'm from India. I hope its liberal there.
Regards,
Blumen
I wish to become a software consultant.
|
|
|
|
|
Quit and find a better company. Well, find a better compnay first, then quit. If the search engines are useless to you, I don't see how they can expect you to find solutions to problems without the 'Net.
I'm in the US and in the company I work for, there are no blocks on where I can go.
|
|
|
|
|
Balagurunathan S wrote: Dont reply asking to try in google...
Why not?
If google can't do it, then look at Sharpdevelop because they have a tool for converting VB.NET to C#. I haven't worked with it in a long time, so I don't know how well it converts...
|
|
|
|
|
SharpDevelope's conversion tool for VB-C# isn't that good. C#-VB support is OK though. I find that when converting VB-C# code, SharpDevelop doesn't take into account VB Optional keyword. It leaves it in there, and of course the C# compiler doesn't understand it. I had to really revamp my code and include support for multiple extra functions before I got my app working OK.;)
|
|
|
|
|
There are some RASEnumEntries projects written in VB6. However there isn't any project written in vb.net in the Internet. I have tried converting a VB6 project into VB.Net but i hit the 632 - Invalid size error. Can someone enlighted me? Here are part of my source code:
'Structure for RASENTRYNAME (Did i get the structure rite?)
'==============================================
Private Structure RAS_ENTRIES
Dim dwFlags As Integer
Dim dwSize As Integer
<vbfixedarray(256)> Dim szEntryname() As Byte
Public Sub Initialize()
ReDim szEntryname(256)
End Sub
End Structure
'==============================================
Function RasEnumEntriesA (Am i assigning the correct structure size?)
'==============================================
Dim lngSize As Integer
Dim lngEntries As Integer
Dim lngIndex As Integer
Dim result As Long
Dim RAS(255) As RAS_ENTRIES
Erase sDunList
RAS(0).dwSize = Marshal.SizeOf(RAS(0))
lngSize = 256 * RAS(0).dwSize
result = RasEnumEntriesA(vbNullString, vbNullString, RAS(0), lngSize, lngEntries)
'================================================
Any help is appreciated. Thanks alot!
Regards,
Max
|
|
|
|
|
It's a pain converting from VB6 to VB.NET, especially when you start calling into the Win32 API. VB6 and VB.NET differ in the way functon parameters are mashaled back and forth. This call in particular, is a b**** to get running.
First, you need to clean up the RAS_ENTRIES structure a bit. You need to tell the .NET CLR how to pack structure members together and how to pass the strings so it matches what the API expects. You also have to tell the CLR what the maximum size the strings are going to be when they are marshaled back to managed code.
<StructLayout(LayoutKind.Sequential,CharSet:=CharSet.Unicode)> _
Public Structure RASENTRYNAME
Public dwSize As Integer
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=257)> Public szEntryName As String
Public dwFlags As Integer
<MarshalAs(UnmanagedType.ByValTStr,SizeConst=261)> Public szPhonebook As String
End Structure
You didn't post what you put for the Declare, but it should look something like this:
Private Declare Auto Function RasEnumEntries Lin "rasapi32" ( _
ByVal reserved As String, _
ByVal phonebook As String, _
<[In](), Out()> ByVal RasEntries() AS RASENTRYNAME, _
ByRef BufferSize As Integer, _
ByRef EntryCount As Integer) _
As Integer
To call it, you have to be a little careful. You have to create an empty dummy entry and set the entries internal structure size before you call this function:
Dim bufferSize As Integer = Marshal.SizeOf(GetType(RASENTRYNAME))
Dim entryCount As Integer = 1
Dim entryNames(0) As RASENTRYNAME
Dim returnCode As Integer
entryNames(0).dwSize = Marshal.SizeOf(GetType(RASENTRYNAME))
rc = RasEnumEntries(Nothing, Nothing, entryNames, bufferSize, entryCount)
If rc = 0 Then
' Return, there was only one entry and it's been filled into the "dummy"
' entry that we made before calling RasEnumEntries.
End If
If rc <> 603 Then
' So if we get here, the call bombed. It would be a good idea to find out why here!
Return
End If
' 603 means that there are more entries than we have allocated space for.
' So, expand the entryNames array and make sure we fill in the structure size
' for every entry in the array! This is important!! Without it, you'll get 632 errors!
ReDim entryNames(numEntries - 1)
For i As Integer = 0 to numEntries - 1
entryNames(i).dwSize = Marshal.SizeOf(GetType(RASENTRYNAME))
Next
rc = RasEnumEntries(Nothing, Nothing, entryNames, bufferSize, entryCount)
'
' Now we should have all the Ras entries. Do with as you will...
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Hi Dave,
I got your advise. Finally the codes are running fine with the result i want.
Many thanks to u!!
Best Rdgs,
Max
|
|
|
|
|
@Dave: your code works perfectly, but on my side some cleanup was required.
So I decided to post a complete and clean version...
Private Const MAX_PATH As Integer = 260 + 1
Private Const MAX_RAS_ENTRY_NAMES As Integer = 256 + 1
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> _
Public Structure RASENTRYNAME
Public dwSize As Integer
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MAX_RAS_ENTRY_NAMES)> _
Public szEntryName As String
Public dwFlags As Integer
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MAX_PATH)> _
Public szPhonebook As String
End Structure
Private Declare Auto Function RasEnumEntries Lib "rasapi32.dll" ( _
ByVal reserved As String, _
ByVal phonebook As String, _
<[In](), Out()> ByVal RasEntries() As RASENTRYNAME, _
ByRef BufferSize As Integer, _
ByRef EntryCount As Integer _
) As Integer
''' <summary>
''' Returns an array with available RAS connection names
''' </summary>
Public Shared Function GetConnectionsNames() As String()
Dim res As New List(Of String)
Try
Dim bufferSize As Integer = Marshal.SizeOf(GetType(RASENTRYNAME))
Dim entryCount As Integer = 1
Dim entryNames(0) As RASENTRYNAME
Dim rc As Integer
entryNames(0).dwSize = Marshal.SizeOf(GetType(RASENTRYNAME))
rc = RasEnumEntries(Nothing, Nothing, entryNames, bufferSize, entryCount)
If rc = 0 Then
' There was only one entry and it's been filled into the "dummy"
' entry that we made before calling RasEnumEntries.
res.Add(entryNames(0).szEntryName.Trim)
ElseIf rc = 603 Then
' 603 means that there are more entries than we have allocated space for.
' So, expand the entryNames array and make sure we fill in the structure size
' for every entry in the array! This is important!! Without it, you'll get 632 errors!
ReDim entryNames(entryCount - 1)
For i As Integer = 0 To entryCount - 1
entryNames(i).dwSize = Marshal.SizeOf(GetType(RASENTRYNAME))
Next
rc = RasEnumEntries(Nothing, Nothing, entryNames, bufferSize, entryCount)
For i As Integer = 0 To entryCount - 1
res.Add(entryNames(i).szEntryName.Trim)
Next
Else
' So if we get here, the call bombed. It would be a good idea to find out why here!
MsgBox("Error reading RAS connections names, error code:" & rc.ToString(), MsgBoxStyle.SystemModal)
End If
Catch ex As Exception
MsgBox("Error reading RAS connection names: " & ex.Message.ToString(), MsgBoxStyle.SystemModal)
End Try
Return res.ToArray
End Function
Thanks again.
Caudio
|
|
|
|
|
works good Seven64
merci beaucoup
quoi de 9 docteur
|
|
|
|
|
|
Have you resolved this?
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
yep needed to twink it a little. but it works fine now ended up using an dll file i got online thouh to do the remoting that is
|
|
|
|
|
Glad you got it to work
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|
hi i am trying to send a int data from1 pc running an window applcation to another pc running another window application.
i tried remoting but it seems too hard is there an easier way to do this please help
|
|
|
|
|
Hi,
I believe Socket programming would be suitable here, and its not that complicated.Try this:
http://www.codeproject.com/cs/internet/socketsincsharp.asp
blumen
|
|
|
|
|