x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

TCP/UDP problem with ISocketSubsystem

Hello guys, I am playing around with the UDP/TCP Sockets of Unreal Engine 4 and got some problems while using the namespaces and functions like the documentation told me how to implement these.

Quiet simple here is just my test Header file: #include "Kismet/BlueprintFunctionLibrary.h" #include "Runtime/Sockets/Public/Sockets.h" #include "Runtime/Networking/Public/Interfaces/IPv4/IPv4Address.h" #include "Runtime/Core/Public/Templates/SharedPointer.h" #include "Runtime/Sockets/Public/SocketSubsystem.h" #include "Runtime/Networking/Public/Networking.h" #include "Runtime/Sockets/Private/BSDSockets/SocketsBSD.h" //#include "Runtime/Sockets/Private/BSDSockets/SocketSubsystemBSD.h" #include "TCPConnection.generated.h"

 /**
  * 
  */
 UCLASS(BlueprintType, Blueprintable)
 class UTCPConnection : public UBlueprintFunctionLibrary
 {
     GENERATED_UCLASS_BODY()
 
 
 
     
     UFUNCTION(BlueprintCallable, Category = "TCPConnection")
     void sendPacket();
     
 
     
     
 };


And my CPP class:

 // Fill out your copyright notice in the Description page of Project Settings.
 
 #include "TCPTest.h"
 #include "TCPConnection.h"
 
 
 
 UTCPConnection::UTCPConnection(const class FObjectInitializer& PCIP)
 : Super(PCIP)
 {
     
 
 }
 
 
 void UTCPConnection::sendPacket(){
 
     
     
     //FSocket* Socket = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateSocket(NAME_Stream, TEXT("default"), false);
     FSocketBSD* Socket = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateSocket(NAME_Stream, TEXT("default"), false);
     
     
     FString address = TEXT("127.0.0.1");
     int32 port = 12345;
     FIPv4Address ip;
     //FIPv4Address::Parse(address, ip);
     ip = FIPv4Address(127, 0, 0, 1);
     
     
     
 
     //TSharedRef<UTCPConnection> addr = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateInternetAddr();
     //auto addr = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateInternetAddr();
     TSharedRef<FInternetAddr> addr = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateInternetAddr();
     addr->SetIp(ip.GetValue());
     addr->SetPort(port);
 
     bool connected = Socket->Connect(*addr);
 
     FString serialized = TEXT("teststring|999");
     TCHAR *serializedChar = serialized.GetCharArray().GetData();
     int32 size = FCString::Strlen(serializedChar);
     int32 sent = 0;
 
     bool successful = Socket->Send((uint8*)TCHAR_TO_UTF8(serializedChar), size, sent);
 }
 

So some functions inside the documentation are a bit outdated and not reliable or replicatable for me. For example I used the "Fsocket" before and noticed that it is not supported from Windows anymore so I have to use FSocketBSD instead.

I am also not able to use the ISocketSubsystem like all the old tutorials or codes found on the forums or answerhub.

VS is underlining "ISocketSubsystem" inside these following lines:

 FSocketBSD* Socket = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateSocket(NAME_Stream, TEXT("default"), false);

and

 TSharedRef<FInternetAddr> addr = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateInternetAddr();



I also noticed that there is an undocumented Class called "FSocketSubsystemBSD" which could fix this maybe but I generally don't have a plan how to use this class. Maybe you'll have some ideas for me :)

Greetings and ty guys

Product Version: Not Selected
Tags:
more ▼

asked Feb 26 '15 at 09:43 PM in C++ Programming

avatar image

3HMonkey
287 14 18 199

avatar image 3HMonkey Feb 28 '15 at 12:08 PM

I forgot: This comes up in 4.6.1 & 4.7.0 release I also had to include all these :

 #include "Kismet/BlueprintFunctionLibrary.h" 
 #include "Runtime/Sockets/Public/Sockets.h" 
 #include "Runtime/Networking/Public/Interfaces/IPv4/IPv4Address.h" 
 #include "Runtime/Core/Public/Templates/SharedPointer.h" 
 #include "Runtime/Sockets/Public/SocketSubsystem.h" 
 #include "Runtime/Networking/Public/Networking.h" 
 #include "Runtime/Sockets/Private/BSDSockets/SocketsBSD.h" 
 //#include "Runtime/Sockets/Private/BSDSockets/SocketSubsystemBSD.h"
  #include "TCPConnection.generated.h"


because: #include "Networking.h" #include "Sockets.h"

was not working, also after including it here:

 PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "Sockets", "Networking" });
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

I didn't have a problem using FSocket on windows in 4.7.1

.h - I only included these 3

 #include "Networking.h"
 #include "Sockets.h"
 #include "SocketSubsystem.h"

.cpp - my connect function. My implimentation is still very much a prototype, hence the UE_LOG and placeholder SOCKETNAME

 void ConnectionManager::Connect(FIPv4Address ip, int32 port)
 {
     UE_LOG(LogTemp, Warning, TEXT("ConnectionManager::Init"));
 
     TSharedRef<FInternetAddr> addr = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateInternetAddr();
     addr->SetIp(ip.GetValue());
     addr->SetPort(port);
 
     TCPSocket = FTcpSocketBuilder("SOCKETNAME").AsNonBlocking().AsReusable().Build();
 
 
     UE_LOG(LogTemp, Warning, TEXT("Socket created! Connecting to server..."));
     bool didConnect = TCPSocket->Connect(*addr);
     if (didConnect)
     {
         UE_LOG(LogTemp, Warning, TEXT("Connection state: true"));
 
         //Create GameClient
         GameClientInstance = new GameClient();
 
         //Check for updates
         TickDelegateHandle = FTicker::GetCoreTicker().AddTicker(FTickerDelegate::CreateRaw(this, &ConnectionManager::Tick), 0.1f);
     }
     else
     {
         UE_LOG(LogTemp, Warning, TEXT("Connection state: false"));
     }
 }



more ▼

answered Mar 03 '15 at 04:57 AM

avatar image

Worrom
78 2 7 11

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question