|
-
Jul 29th, 2004, 08:11 PM
#1
Thread Starter
Member
[Resolved] Socket Question
I am getting an error while trying to load the same form 2 times in an MDI Container BUT each form has a new Port to bind to.
This is the error.
An unhandled exception of type 'System.Net.Sockets.SocketException' occurred in system.windows.forms.dll
Additional information: Only one usage of each socket address (protocol/network address/port) is normally permitted
Last edited by dsc_chris; Aug 1st, 2004 at 09:50 AM.
-
Jul 29th, 2004, 10:06 PM
#2
Addicted Member
if you want, you can look into the TCPClient and TCPListener's class
-
Jul 30th, 2004, 08:19 AM
#3
yay gay
I think it happens because you are trying to connect 2 times with the same connection
\m/  \m/
-
Jul 30th, 2004, 02:07 PM
#4
Thread Starter
Member
I think i figured it out just now i gotta get around it. You see the 1 single form which i wanna load multiple times in an mdi form grabs stuff from a mysql database. well during form load I have the MDI form assigning it a profile id. But that is being assigned in a function and that function is setting the profile_id to a label for storage. Well the stuff which handles the mysql connection and the socket binding is linked to the profile id that way it pulls all the information from the user's account from the mysql database and only loads on what the DB tells it to. Now it would appear things are trying to connect to the database before the form is fully loaded which might be giving me that socket error because it cant bind to an ip since there is no ip, nor can it bind to a port since there is no port since it cant conncect to the database. Any help would be appreciated I just simply need to know how to wait until the form loads to process any of the stuff
-
Jul 30th, 2004, 02:15 PM
#5
Frenzied Member
Just like PT Exorcist said. I've seen that error when I've tried to open a socket, but there's already a socket open on that same IP and port. Maybe put some debugging in there and show what port you're attempting to connect to.
But if you really think you need to wait until after Form_Load to do some stuff, create another method, like InitializeForm, then call this right after you call your Form.Show()
-
Jul 30th, 2004, 02:37 PM
#6
Thread Starter
Member
Mike, that is exactly what the issue is due to it pulling the stuff from the same table in the database instead of grabbing the info from the label of the stored profile ip it cant connect to the database therefore it really tries to bind to nothing on the system since it cant access the database. Problem with putting everything into a function or a sub is that I cant get it to make the variables global to the entire project I tried putting this in a module but i get an error as well there it seems like everything only works if it is in the Form's main area problem with doing that is some of the stuff it is calling is in a module. I could try moving that to form specific and going from there.
-
Jul 30th, 2004, 02:58 PM
#7
Thread Starter
Member
Ok, I tried that now the new error I am getting is
An unhandled exception of type 'System.NullReferenceException' occurred in DarkGSP dot NET Dev.exe
Additional information: Object reference not set to an instance of an object.
This is when I tried to
VB Code:
Public ID As Integer = Me.lblId.Text
-
Jul 30th, 2004, 03:29 PM
#8
Frenzied Member
Are you trying to do that so it's a public variable in your class? If so, you can't do that. You could declare the variable, but you can't set the value to one of your components that doesn't exist yet.
-
Jul 31st, 2004, 08:01 PM
#9
Thread Starter
Member
I have kind of tracked down the problem I am actually having.
What I NEED to do is this I have a public variable in the Public Class area of frmDarkGSP directly under Inherits System.Windows.Forms.Form I assume this is the same thing like vb6 called it the public declarations area. Anyways it would appear after doing some debugging the error is the fact that
VB Code:
Public user_id As String = Me.lblProfileID.Text
This code isnt even grabbing what is in the label field of lblProfileID.Text I have tried it with and without the Me. statement. What am I doing wrong why cant I grab that information from the text box? The thing is I want this only to be form specific as each form will obviously have a new ID in the label everytime it is loaded. I will end up changing that to Private user_id i am sure.
UPDATE:
This is the error message and it highlights that line above
Code:
An unhandled exception of type 'System.NullReferenceException' occurred in DarkGSP dot NET Dev.exe
Additional information: Object reference not set to an instance of an object.
-
Aug 1st, 2004, 09:32 AM
#10
Frenzied Member
I think the reason you can't do that is because you're trying to assign a variable to the value of an object, but the object doesn't exist yet. You could set it to a constant.
Maybe try declaring your variable there, but do the assignment in Form_Load?
-
Aug 1st, 2004, 09:48 AM
#11
Thread Starter
Member
I have kind of been trying other things. Since the form is not visible during the Dim DarkGSP as New frmDarkGSP call I just put before that in the MDI form the variable i need and put that specific variable in the modFunctions module
Example:
VB Code:
modFunctions.user_id = myReader.GetString(0)
Dim DarkGSP As New frmDarkGSP
DarkGSP.TopLevel = False
DarkGSP.Parent = pnlMain
DarkGSP.Profile_ID(myReader.GetString(0))
DarkGSP.Show()
This solved the issue with the variable not coming up. Now to make SURE it was processing the right stuff before the form became visible I simply put an If-Else-EndIf statement in there to check if the form is visible if it is not it process's using the variable, if the form is visible it process's using the Profile_ID field which writes the information to a label. This seems to have fixed it I know I can probably do it better but this will have to do until i can get a better hand on .NET as I have only been doing .NET for 2 weeks it is much much different from vb6 
Anyways thanks alot again mike for your help. Your awsome man
Regards,
Chris Childers
DarkStar Communications
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|