Jump to content

Transmitting video capture from server to client (Newbie)

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
30 replies to this topic

#1
MrNobody

MrNobody

    Newbie

  • Members
  • PipPip
  • 23 posts
Hi..
Attached is a code to capture a USB webcam.
If i want to use the code as a server, what do i need to add to it..?
Preferably, sending using UDP.. can somebody please advise..

After that, I want to write a client program.. but that is later..

By the way, I am new to Visual Basic, so, help is needed and appreciated.
Thanks..

Attached Files



#2
Lop

Lop

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,172 posts
Without downloading and looking at the code... Are you using .NET or VB 6.0?

In .NET you can use the System.Net.Sockets.UdpClient

Here is the code for the TcpClient though:

private void ConnectAndSend(String ip, String Msg, int port)
        {
            // Connect to our socket
            TcpClient msgClient;


            // Try to connect
            msgClient = new TcpClient(textBox1.Text, port);

            // Create our network stream
            NetworkStream networkStream = msgClient.GetStream();
            System.IO.StreamReader streamReader = new System.IO.StreamReader(networkStream);
            System.IO.StreamWriter streamWriter = new System.IO.StreamWriter(networkStream);

            // Write our message
            try
            {
                streamWriter.WriteLine(Msg);
                streamWriter.Flush();
            }
            catch (System.Exception e)
            {
                MessageBox.Show(e.ToString());
            }

            // Disconnect
            msgClient.Close();

        }


#3
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Lop, that looks like C# code instead of VB.

MrNobody, I've copied your post into the code section, I hope this is alright.

http://forum.codecal...usb-camera.html

#4
MrNobody

MrNobody

    Newbie

  • Members
  • PipPip
  • 23 posts
Lop:
Thanks for the reply and the code...
I am using VB 6.0. Here are a few things i need help with..

1) How do I convert the VB 6 code into VB.net..?
2) How do i change the code to make it UDP instead of TCP, because i need a fast transmission.. I don't mind loosing a few frames..
3) Can I compile the code as it is or do I need to add something else to it..?
4) How do I create a server with the webcam code added to it..?

Honestly, this is the first VB 6 program i compiled... So, sorry if i ask silly questions...


Jordan:
Sure u can put the code in the code section.. I don't mind..

#5
Lop

Lop

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,172 posts
This code is ready to be compiled and ran:

http://forum.codecal...ger-client.html

Just download the attachment.

1) For converting to .NET - that is harder than said.
2) Wherever you see TcpClient use System.Net.Sockets.UdpClient or just UdpClient if you have that namespace decalred.
3) Yes, if you download the attachment
4) You will need to rewrite this in .NET if you choose to use that. I suggest you create it in .NET because I couldn't find anything on vb 6 and TCP.

Here is a tutorial:
http://www.codeproje...net/TinyUDP.asp

#6
MrNobody

MrNobody

    Newbie

  • Members
  • PipPip
  • 23 posts
Lop:

I went to:-
http://forum.codecal...ger-client.html

But there it said:-
"This is the client, which is not in C++ but C# .NET 2.0 for"

Is C#.Net the same as VB.net..? I am very new to .Net...

#7
Lop

Lop

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,172 posts
No, C# is not the same as VB but when using the .NET language it is very easy to port. VB and C# have all of the same classes, methods, functions, and namespaces so you just need to change the way the code is called.

I don't know VB that well so I can't give an example. Sorry.

#8
MrNobody

MrNobody

    Newbie

  • Members
  • PipPip
  • 23 posts
Hi.. I managed to find a simple client/server using UDP in VB 6.0 to send message..
Below is the code.. The code is taken from

http://homepages.ius...tagram Services

I just change the form caption only..
Does anybody know how I can edit both the code so that I can send Webcam Stream from server to client instead of sending messages..?
Thanks..


Lop:
I tried those C# to VB.net converter tools to convert the code but it does not work.. Maybe its because of different version of VB.net.. I am using VB Express 2005.. its ok.. thanks anyway..

Attached Files



#9
dirkfirst

dirkfirst

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 354 posts
I didn't even know there was a C# to VB.net converter!

I can't see the code because I don't have VB 6. Can you post the section for sending messages? It would probably be a simple matter of adding a loop and streaming the media.

#10
MrNobody

MrNobody

    Newbie

  • Members
  • PipPip
  • 23 posts

dirkfirst said:

I didn't even know there was a C# to VB.net converter!

I can't see the code because I don't have VB 6. Can you post the section for sending messages? It would probably be a simple matter of adding a loop and streaming the media.
Here is the website http://www.kamalpate...tCSharp2VB.aspx
I am not sure if it works tho...




Anyway, I have found a code for the client/server that capture and transmit webcam stream.
I have attached it below for those who are interested in doing it..

The code uses the code below to capture and send the stream


Private Sub TmrStream_Timer()

On Error Resume Next

TakeFrame

End Sub



Public Sub TakeFrame()

On Error Resume Next

Dim Bjpg As String

If Winsock1.State = sckConnected Then

SavePicture Picture1.Picture, App.Path & "\temp.bsrm"

Call ConvertBMPtoJPG(App.Path & "\temp.bsrm", App.Path & "\temp.jsrm", True, 100, False)

DoEvents

Bjpg = GetFile(App.Path & "\temp.jsrm")

DoEvents

Winsock1.SendData Bjpg

End If

End Sub


I think what it does is it uses the timer to capture a picture, convert it to JPEG and then sending it. Is this method effective..?

I came across other methods such as using DirectShow and AVICap..
Why different methods of doing similar tasks..? Which is the more effective way..?

Attached Files



#11
dirkfirst

dirkfirst

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 354 posts
Hmm, interesting, it does use a timer to take the screenshot. Different versions may be faster or more efficient or they may not. I'm not really sure which would be best though.

So all you want is a screenshot? How often do you receive a screenshot? This seems like a non-effective way to do it.

#12
MrNobody

MrNobody

    Newbie

  • Members
  • PipPip
  • 23 posts

dirkfirst said:

Hmm, interesting, it does use a timer to take the screenshot. Different versions may be faster or more efficient or they may not. I'm not really sure which would be best though.

So all you want is a screenshot? How often do you receive a screenshot? This seems like a non-effective way to do it.
Umm.. actually, i would prefer webcam stream using UDP.. not the screenshot.. but i don't know how... i mean, the process of doing it..
With the timer, i understand the process is take a snapshot, save the pic, convert the pic to jpeg and then send the jpeg file..
How about sending the whole stream..? how do i do it..?